First of all, Hallo I am new to ACCPAC and so also new to this forumns....I sound like Alcohol anonymous person....lol..anycase.
I am trying to Insert Payments into Accpca using c#. I got it to work on the Purchase orders,by just recreating the macro using c#, and it seems to work 100% , but when recreating the macro in C# for the payments I get com exception on the record create and update see code at the bottom
ACCPAC.Advantage.Session AccSession = new ACCPAC.Advantage.Session();
AccSession.Init("", "AP", "AP3100", "54A");
AccSession.Open("*****", "*****", "****", DateTime.Now.AddYears(-1), 0);
ACCPAC.Advantage.DBLink PmtCompLink = AccSession.OpenDBLink(ACCPAC.Advantage.DBLinkType.Company, ACCPAC.Advantage.DBLinkFlags.ReadWrite);
ACCPAC.Advantage.DBLink PmtSysLink = AccSession.OpenDBLink(ACCPAC.Advantage.DBLinkType.System, ACCPAC.Advantage.DBLinkFlags.ReadWrite);
bool temp = false;
ACCPAC.Advantage.ViewFields APPaymentBatchFields;
ACCPAC.Advantage.View APPaymentBatch = PmtCompLink.OpenView("AP0030");
APPaymentBatchFields = APPaymentBatch.Fields;
ACCPAC.Advantage.ViewFields APPaymentHeaderFields;
ACCPAC.Advantage.View APPaymentHeader = PmtCompLink.OpenView("AP0031");//header
APPaymentHeaderFields = APPaymentHeader.Fields;
ACCPAC.Advantage.ViewFields APPaymentDetail1Fields;
ACCPAC.Advantage.View APPaymentDetail1 = PmtCompLink.OpenView("AP0033"); //DETAILVIEWS
APPaymentDetail1Fields = APPaymentDetail1.Fields;
ACCPAC.Advantage.ViewFields APPaymentDetail2Fields;
ACCPAC.Advantage.View APPaymentDetail2 = PmtCompLink.OpenView("AP0034");
APPaymentDetail2Fields = APPaymentDetail2.Fields;
ACCPAC.Advantage.ViewFields APPaymentDetail3Fields;
ACCPAC.Advantage.View APPaymentDetail3 = PmtCompLink.OpenView("AP0032");
APPaymentDetail3Fields = APPaymentDetail3.Fields;
ACCPAC.Advantage.ViewFields APPaymentDetail4Fields;
ACCPAC.Advantage.View APPaymentDetail4 = PmtCompLink.OpenView("AP0048");
APPaymentDetail4Fields = APPaymentDetail4.Fields;
ACCPAC.Advantage.ViewFields APPaymentDetail5Fields;
ACCPAC.Advantage.View APPaymentDetail5 = PmtCompLink.OpenView("AP0406");
APPaymentDetail5Fields = APPaymentDetail5.Fields;
ACCPAC.Advantage.View[] APPaymentBatch1 = new ACCPAC.Advantage.View[1] { APPaymentHeader };
APPaymentBatch.Compose(APPaymentBatch1);
ACCPAC.Advantage.View[] APHeaderBatch = new ACCPAC.Advantage.View[4] { APPaymentBatch, APPaymentDetail3, APPaymentDetail1, APPaymentDetail5 };
APPaymentHeader.Compose(APHeaderBatch);
//Compose detail views.
ACCPAC.Advantage.View[] APDetailBatch1 = new ACCPAC.Advantage.View[3] { APPaymentHeader, APPaymentDetail2, APPaymentDetail4 };
APPaymentDetail1.Compose(APDetailBatch1);
ACCPAC.Advantage.View[] APDetailBatch2 = new ACCPAC.Advantage.View[1] { APPaymentDetail1 };
APPaymentDetail2.Compose(APDetailBatch2);
ACCPAC.Advantage.View[] APDetailBatch3 = new ACCPAC.Advantage.View[1] { APPaymentHeader };
APPaymentDetail3.Compose(APDetailBatch3);
ACCPAC.Advantage.View[] APDetailBatch4 = new ACCPAC.Advantage.View[5] { APPaymentBatch, APPaymentHeader, APPaymentDetail3, APPaymentDetail1, APPaymentDetail2 };
APPaymentDetail4.Compose(APDetailBatch4);
ACCPAC.Advantage.View[] APDetailBatch5 = new ACCPAC.Advantage.View[1] { APPaymentHeader };
APPaymentDetail5.Compose(APDetailBatch5);
temp = APPaymentBatch.Exists;
APPaymentBatch.RecordClear();
APPaymentBatchFields.FieldByName("PAYMTYPE").SetValue("PY", false); //batch selector
APPaymentHeaderFields.FieldByName("BTCHTYPE").SetValue("PY", false); //batch type/
APPaymentDetail3Fields.FieldByName("BATCHTYPE").SetValue("PY", false);
APPaymentDetail1Fields.FieldByName("BATCHTYPE").SetValue("PY", false);
APPaymentDetail2Fields.FieldByName("BATCHTYPE").SetValue("PY", false);
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentBatch.Browse(@"((PAYMTYPE='PY') AND ((BATCHSTAT=1) OR (BATCHSTAT=7) OR (BATCHSTAT=8)))", true);
APPaymentBatchFields.FieldByName("PAYMTYPE").SetValue("PY", false);
APPaymentBatchFields.FieldByName("CNTBTCH").SetValue(0, false);
temp = APPaymentBatch.Exists;
APPaymentBatch.RecordCreate(ACCPAC.Advantage.ViewRecordCreate.Insert );
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
//***********************************
//This gives com exeption
APPaymentHeader.RecordCreate(ACCPAC.Advantage.ViewRecordCreate.Insert);
//****************************************
//APPAYMENT1header.RecordCreate 0
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentBatchFields.FieldByName("BATCHDESC").SetValue("SDFSDFSD", false);
//*********************************************
//********THIS IS WHERE I GET THE EXCEPTION****
APPaymentBatch.Update(); //Create Batch Header
//*********************************************
//*********************************************
APPaymentHeaderFields.FieldByName("TEXTRMIT").SetValue("sdsds", false);
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentHeaderFields.FieldByName("RMITTYPE").SetValue("4", false);
APPaymentDetail1.Cancel();
APPaymentHeaderFields.FieldByName("PROCESSCMD").SetValue("0", false);
APPaymentHeader.Process();
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentHeaderFields.FieldByName("IDVEND").SetValue("GOE-1234", false);
APPaymentDetail1.Cancel();
APPaymentHeaderFields.FieldByName("PROCESSCMD").SetValue("0", false);
APPaymentHeader.Process();
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentHeaderFields.FieldByName("SWPRNTRMIT").SetValue("0", false);
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentHeaderFields.FieldByName("TXTRMITREF").SetValue("sdsdsd", false);
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentHeaderFields.FieldByName("IDINVCMTCH").SetValue("sdsds", false); //matching document number
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentDetail3.Exists;
APPaymentDetail3.RecordClear();
temp = APPaymentDetail3.Exists;
APPaymentDetail3.RecordCreate(0);
APPaymentDetail3Fields.FieldByName("GLDESC").SetValue("sdsd", false); //GL description
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentDetail3Fields.FieldByName("IDACCT").SetValue("32423-343-454-454-45-454-454", false); ///account number
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentDetail3Fields.FieldByName("AMTDISTTC").SetValue("3400.00", false); //dist ammount
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentDetail3Fields.FieldByName("GLREF").SetValue("asdasD", false); //GL reference
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentDetail3.Insert();
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentDetail3Fields.FieldByName("CNTLINE").SetValue("-1", false); //line number
APPaymentDetail3Fields.FieldByName("CNTLINE").SetValue("-1", false); //line number
APPaymentDetail3.Read(false);
temp = APPaymentDetail3.Exists;
APPaymentDetail3.RecordCreate(0);
APPaymentDetail3Fields.FieldByName("CNTLINE").SetValue("-1", false); //line number
APPaymentDetail3.Read(false);
APPaymentDetail3.Insert();
APPaymentHeaderFields.FieldByName("SWPRNTRMIT").SetValue("1", false); //check print required
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentBatch.Read(false);
APPaymentHeaderFields.FieldByName("CNTENTR").SetValue("0", false); //entry number
temp = APPaymentHeader.Exists;
APPaymentHeader.RecordCreate(0);
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
Thanks in advance for any help
V3nd3tta
I am trying to Insert Payments into Accpca using c#. I got it to work on the Purchase orders,by just recreating the macro using c#, and it seems to work 100% , but when recreating the macro in C# for the payments I get com exception on the record create and update see code at the bottom
ACCPAC.Advantage.Session AccSession = new ACCPAC.Advantage.Session();
AccSession.Init("", "AP", "AP3100", "54A");
AccSession.Open("*****", "*****", "****", DateTime.Now.AddYears(-1), 0);
ACCPAC.Advantage.DBLink PmtCompLink = AccSession.OpenDBLink(ACCPAC.Advantage.DBLinkType.Company, ACCPAC.Advantage.DBLinkFlags.ReadWrite);
ACCPAC.Advantage.DBLink PmtSysLink = AccSession.OpenDBLink(ACCPAC.Advantage.DBLinkType.System, ACCPAC.Advantage.DBLinkFlags.ReadWrite);
bool temp = false;
ACCPAC.Advantage.ViewFields APPaymentBatchFields;
ACCPAC.Advantage.View APPaymentBatch = PmtCompLink.OpenView("AP0030");
APPaymentBatchFields = APPaymentBatch.Fields;
ACCPAC.Advantage.ViewFields APPaymentHeaderFields;
ACCPAC.Advantage.View APPaymentHeader = PmtCompLink.OpenView("AP0031");//header
APPaymentHeaderFields = APPaymentHeader.Fields;
ACCPAC.Advantage.ViewFields APPaymentDetail1Fields;
ACCPAC.Advantage.View APPaymentDetail1 = PmtCompLink.OpenView("AP0033"); //DETAILVIEWS
APPaymentDetail1Fields = APPaymentDetail1.Fields;
ACCPAC.Advantage.ViewFields APPaymentDetail2Fields;
ACCPAC.Advantage.View APPaymentDetail2 = PmtCompLink.OpenView("AP0034");
APPaymentDetail2Fields = APPaymentDetail2.Fields;
ACCPAC.Advantage.ViewFields APPaymentDetail3Fields;
ACCPAC.Advantage.View APPaymentDetail3 = PmtCompLink.OpenView("AP0032");
APPaymentDetail3Fields = APPaymentDetail3.Fields;
ACCPAC.Advantage.ViewFields APPaymentDetail4Fields;
ACCPAC.Advantage.View APPaymentDetail4 = PmtCompLink.OpenView("AP0048");
APPaymentDetail4Fields = APPaymentDetail4.Fields;
ACCPAC.Advantage.ViewFields APPaymentDetail5Fields;
ACCPAC.Advantage.View APPaymentDetail5 = PmtCompLink.OpenView("AP0406");
APPaymentDetail5Fields = APPaymentDetail5.Fields;
ACCPAC.Advantage.View[] APPaymentBatch1 = new ACCPAC.Advantage.View[1] { APPaymentHeader };
APPaymentBatch.Compose(APPaymentBatch1);
ACCPAC.Advantage.View[] APHeaderBatch = new ACCPAC.Advantage.View[4] { APPaymentBatch, APPaymentDetail3, APPaymentDetail1, APPaymentDetail5 };
APPaymentHeader.Compose(APHeaderBatch);
//Compose detail views.
ACCPAC.Advantage.View[] APDetailBatch1 = new ACCPAC.Advantage.View[3] { APPaymentHeader, APPaymentDetail2, APPaymentDetail4 };
APPaymentDetail1.Compose(APDetailBatch1);
ACCPAC.Advantage.View[] APDetailBatch2 = new ACCPAC.Advantage.View[1] { APPaymentDetail1 };
APPaymentDetail2.Compose(APDetailBatch2);
ACCPAC.Advantage.View[] APDetailBatch3 = new ACCPAC.Advantage.View[1] { APPaymentHeader };
APPaymentDetail3.Compose(APDetailBatch3);
ACCPAC.Advantage.View[] APDetailBatch4 = new ACCPAC.Advantage.View[5] { APPaymentBatch, APPaymentHeader, APPaymentDetail3, APPaymentDetail1, APPaymentDetail2 };
APPaymentDetail4.Compose(APDetailBatch4);
ACCPAC.Advantage.View[] APDetailBatch5 = new ACCPAC.Advantage.View[1] { APPaymentHeader };
APPaymentDetail5.Compose(APDetailBatch5);
temp = APPaymentBatch.Exists;
APPaymentBatch.RecordClear();
APPaymentBatchFields.FieldByName("PAYMTYPE").SetValue("PY", false); //batch selector
APPaymentHeaderFields.FieldByName("BTCHTYPE").SetValue("PY", false); //batch type/
APPaymentDetail3Fields.FieldByName("BATCHTYPE").SetValue("PY", false);
APPaymentDetail1Fields.FieldByName("BATCHTYPE").SetValue("PY", false);
APPaymentDetail2Fields.FieldByName("BATCHTYPE").SetValue("PY", false);
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentBatch.Browse(@"((PAYMTYPE='PY') AND ((BATCHSTAT=1) OR (BATCHSTAT=7) OR (BATCHSTAT=8)))", true);
APPaymentBatchFields.FieldByName("PAYMTYPE").SetValue("PY", false);
APPaymentBatchFields.FieldByName("CNTBTCH").SetValue(0, false);
temp = APPaymentBatch.Exists;
APPaymentBatch.RecordCreate(ACCPAC.Advantage.ViewRecordCreate.Insert );
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
//***********************************
//This gives com exeption
APPaymentHeader.RecordCreate(ACCPAC.Advantage.ViewRecordCreate.Insert);
//****************************************
//APPAYMENT1header.RecordCreate 0
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentBatchFields.FieldByName("BATCHDESC").SetValue("SDFSDFSD", false);
//*********************************************
//********THIS IS WHERE I GET THE EXCEPTION****
APPaymentBatch.Update(); //Create Batch Header
//*********************************************
//*********************************************
APPaymentHeaderFields.FieldByName("TEXTRMIT").SetValue("sdsds", false);
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentHeaderFields.FieldByName("RMITTYPE").SetValue("4", false);
APPaymentDetail1.Cancel();
APPaymentHeaderFields.FieldByName("PROCESSCMD").SetValue("0", false);
APPaymentHeader.Process();
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentHeaderFields.FieldByName("IDVEND").SetValue("GOE-1234", false);
APPaymentDetail1.Cancel();
APPaymentHeaderFields.FieldByName("PROCESSCMD").SetValue("0", false);
APPaymentHeader.Process();
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentHeaderFields.FieldByName("SWPRNTRMIT").SetValue("0", false);
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentHeaderFields.FieldByName("TXTRMITREF").SetValue("sdsdsd", false);
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentHeaderFields.FieldByName("IDINVCMTCH").SetValue("sdsds", false); //matching document number
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentDetail3.Exists;
APPaymentDetail3.RecordClear();
temp = APPaymentDetail3.Exists;
APPaymentDetail3.RecordCreate(0);
APPaymentDetail3Fields.FieldByName("GLDESC").SetValue("sdsd", false); //GL description
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentDetail3Fields.FieldByName("IDACCT").SetValue("32423-343-454-454-45-454-454", false); ///account number
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentDetail3Fields.FieldByName("AMTDISTTC").SetValue("3400.00", false); //dist ammount
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentDetail3Fields.FieldByName("GLREF").SetValue("asdasD", false); //GL reference
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentDetail3.Insert();
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentDetail3Fields.FieldByName("CNTLINE").SetValue("-1", false); //line number
APPaymentDetail3Fields.FieldByName("CNTLINE").SetValue("-1", false); //line number
APPaymentDetail3.Read(false);
temp = APPaymentDetail3.Exists;
APPaymentDetail3.RecordCreate(0);
APPaymentDetail3Fields.FieldByName("CNTLINE").SetValue("-1", false); //line number
APPaymentDetail3.Read(false);
APPaymentDetail3.Insert();
APPaymentHeaderFields.FieldByName("SWPRNTRMIT").SetValue("1", false); //check print required
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentBatch.Read(false);
APPaymentHeaderFields.FieldByName("CNTENTR").SetValue("0", false); //entry number
temp = APPaymentHeader.Exists;
APPaymentHeader.RecordCreate(0);
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
Thanks in advance for any help
V3nd3tta