Code below runs successfully on C#, it's almost direct translation from VB script. Strange, but it doesn't work if I'm using my lib with view names/fields shortcuts, which seems to work well before... May be bug is there.
Thank you, tuba, I'll try to find it myself.
using System;
using ACCPAC.Advantage;
using AIS.CommonClasses;
using AIS.CommonClasses.Exceptions;
using AIS.Datalayer.AccpacViews;
using AIS.DataLayer.AccpacViews.Bank;
namespace Accpac54ConsoleTest
{
class Program
{
static void Main(string[] args)
{
Session sessionMain;
DBLink dbLinkMain;
sessionMain = new Session();
sessionMain.Init("", "CS", "CS0001", "54A");
sessionMain.Open("ADMIN", "SUPER", "EMPTY2", DateTime.Now, 0);
dbLinkMain = sessionMain.OpenDBLink(DBLinkType.Company, DBLinkFlags.ReadWrite);
Console.WriteLine("Start");
try
{
string time = DateTime.Now.ToString("HHmmss");
View ap0020 = dbLinkMain.OpenView("AP0020");
ViewFields ap0020f = ap0020.Fields;
View ap0021 = dbLinkMain.OpenView("AP0021");
ViewFields ap0021f = ap0021.Fields;
View ap0021o = dbLinkMain.OpenView("AP0402");
ViewFields ap0021of = ap0021o.Fields;
View ap0022 = dbLinkMain.OpenView("AP0022");
ViewFields ap0022f = ap0022.Fields;
View ap0022o = dbLinkMain.OpenView("AP0401");
ViewFields ap0022of = ap0022o.Fields;
View ap0023 = dbLinkMain.OpenView("AP0023");
ViewFields ap0023f = ap0023.Fields;
ap0020.Compose(new View[] { ap0021 });
ap0021.Compose(new View[] { ap0020, ap0022, ap0023, ap0021o });
ap0022.Compose(new View[] { ap0021, ap0020 });
ap0022.Compose(new View[] { ap0021, ap0020, ap0022o });
ap0023.Compose(new View[] { ap0021 });
ap0021o.Compose(new View[] { ap0021 });
ap0022o.Compose(new View[] { ap0022 });
ap0020.Browse("((BTCHSTTS = 1) OR (BTCHSTTS = 7))",true);
ap0020.RecordCreate(ACCPAC.Advantage.ViewRecordCreate.Insert);
ap0020.Read(false);
ap0020f.FieldByName("BTCHDESC").SetValue("batch " + time, false);
ap0020.Update();
for (int i = 0; i < 2; i++)
{
ap0021.RecordCreate(ACCPAC.Advantage.ViewRecordCreate.NoInsert);
ap0022.Cancel();
ap0021f.FieldByName("IDVEND").SetValue("1AH", true);
ap0021f.FieldByName("PROCESSCMD").SetValue("7", false);
ap0021f.FieldByName("INVCDESC").SetValue("entry description"+i.ToString(), false);
ap0021.Process();
ap0021f.FieldByName("PROCESSCMD").SetValue("4", false);
ap0021.Process();
ap0021f.FieldByName("IDINVC").SetValue("VenInvN" + time + "_" + i.ToString(), true); // Document Number
ap0021f.FieldByName("AMTGROSTOT").SetValue(1, true);
ap0021f.FieldByName("DATEINVC").SetValue(DateTime.Now, true);
ap0022f.FieldByName("CNTLINE").SetValue(-1, false);
ap0022.Read(false);
ap0022f.FieldByName("IDDIST").SetValue("1", true);
ap0022f.FieldByName("AMTDIST").SetValue(1, true);
ap0022f.FieldByName("IDGLACCT").SetValue("30300", true);
ap0022f.FieldByName("TAXCLASS1").SetValue(1, true);
ap0022.Update();
ap0021.Insert();
}
Console.WriteLine("Sucessfull...");
Console.ReadLine();
}
catch (Exception ex)
{
for (int i=0; i<dbLinkMain.Parent.Errors.Count; i++)
{
Console.WriteLine(dbLinkMain.Parent.Errors.Message);
}
Console.WriteLine(ex.ToString());
}
}
}
}