Anyone know how to Insert AR Invoice C# ACCPAC.Advantage

SOLVED

I can insert a customer, i can insert a Vendor, but when i try to insert an invoice into AR, i get object set to null errors lol no matter what i do. I've been doing permutations of the code in hopes of finding WHY the error happens, i tried their RVSpy tool to see what is going on, but that just says NOTHING.

My code is simple enough: 

bool temp = false;
ACCPAC.Advantage.View ARINVOICE1batch;
ACCPAC.Advantage.ViewFields ARINVOICE1batchFields;
ARINVOICE1batch = mDBLinkCmpRW.OpenView("AR0031");
ARINVOICE1batchFields = ARINVOICE1batch.Fields;


ACCPAC.Advantage.View ARINVOICE1header;
ACCPAC.Advantage.ViewFields ARINVOICE1headerFields;
ARINVOICE1header = mDBLinkCmpRW.OpenView("AR0032");
ARINVOICE1headerFields = ARINVOICE1header.Fields;

ACCPAC.Advantage.View ARINVOICE1detail1;
ACCPAC.Advantage.ViewFields ARINVOICE1detail1Fields;
ARINVOICE1detail1 = mDBLinkCmpRW.OpenView("AR0033");
ARINVOICE1detail1Fields = ARINVOICE1detail1.Fields;

ACCPAC.Advantage.View ARINVOICE1detail2;
ACCPAC.Advantage.ViewFields ARINVOICE1detail2Fields;
ARINVOICE1detail2 = mDBLinkCmpRW.OpenView("AR0034");
ARINVOICE1detail2Fields = ARINVOICE1detail2.Fields;


ACCPAC.Advantage.View ARINVOICE1detail3;
ACCPAC.Advantage.ViewFields ARINVOICE1detail3Fields;
ARINVOICE1detail3 = mDBLinkCmpRW.OpenView("AR0402");
ARINVOICE1detail3Fields = ARINVOICE1detail3.Fields;

ACCPAC.Advantage.View ARINVOICE1detail4;
ACCPAC.Advantage.ViewFields ARINVOICE1detail4Fields;
ARINVOICE1detail4 = mDBLinkCmpRW.OpenView("AR0401");
ARINVOICE1detail4Fields = ARINVOICE1detail4.Fields;


ACCPAC.Advantage.View[] V1 = new ACCPAC.Advantage.View[1] { ARINVOICE1header };
ARINVOICE1batch.Compose(V1);

ACCPAC.Advantage.View[] V2 = new ACCPAC.Advantage.View[4] { ARINVOICE1batch, ARINVOICE1detail1, ARINVOICE1detail2, ARINVOICE1detail3 };
ARINVOICE1header.Compose(V2);
ACCPAC.Advantage.View[] V3 = new ACCPAC.Advantage.View[3] { ARINVOICE1header, ARINVOICE1batch, ARINVOICE1detail4 };
ARINVOICE1detail1.Compose(V3);
ACCPAC.Advantage.View[] V4 = new ACCPAC.Advantage.View[1] { ARINVOICE1header };
ARINVOICE1detail2.Compose(V4);
ACCPAC.Advantage.View[] V5 = new ACCPAC.Advantage.View[1] { ARINVOICE1header };
ARINVOICE1detail3.Compose(V5);
ACCPAC.Advantage.View[] V6 = new ACCPAC.Advantage.View[1] { ARINVOICE1detail1 };
ARINVOICE1detail4.Compose(V6);

ARINVOICE1batch.Browse("((BTCHSTTS = 1) OR (BTCHSTTS = 7))", true);

ACCPAC.Advantage.View ARINVCPOST2;
ACCPAC.Advantage.ViewFields ARINVCPOST2Fields;
ARINVCPOST2 = mDBLinkCmpRW.OpenView("AR0048");
ARINVCPOST2Fields = ARINVCPOST2.Fields;

ARINVOICE1batch.RecordCreate(ViewRecordCreate.Insert);// 1
ARINVOICE1batchFields.FieldByName("PROCESSCMD").SetValue("1", false);
ARINVOICE1batch.Process();
ARINVOICE1batch.Read(false);
ARINVOICE1header.RecordCreate(ViewRecordCreate.DelayKey);// 2
ARINVOICE1detail1.Cancel();
ARINVOICE1headerFields.FieldByName("IDCUST").SetValue("C01045",false); //<---- *** up
ARINVOICE1headerFields.FieldByName("PROCESSCMD").SetValue("4", false);
ARINVOICE1header.Process();
ARINVOICE1headerFields.FieldByName("IDINVC").SetValue("DOC " + _CUSTID,false);
ARINVOICE1headerFields.FieldByName("INVCTYPE").SetValue("2",false);
temp = ARINVOICE1detail1.Exists;
ARINVOICE1detail1.RecordClear();
temp = ARINVOICE1detail1.Exists;
ARINVOICE1detail1.RecordCreate(ViewRecordCreate.NoInsert);// 0
ARINVOICE1detail1Fields.FieldByName("PROCESSCMD").SetValue("0", false);
ARINVOICE1detail1.Process();
ARINVOICE1detail1Fields.FieldByName("IDDIST").SetValue("11",false);
ARINVOICE1detail1Fields.FieldByName("AMTEXTN").SetValue("666.000",false);
ARINVOICE1detail1Fields.FieldByName("COMMENT").SetValue("20 doors", false);
ARINVOICE1detail1.Insert();
ARINVOICE1detail1Fields.FieldByName("CNTLINE").SetValue("-1", false);
ARINVOICE1detail1.Read(false);
ARINVOICE1headerFields.FieldByName("SPECINST").SetValue("instructions", false);
ARINVOICE1headerFields.FieldByName("ORDRNBR").SetValue("MY ORDER" + _CUSTID, false);
ARINVOICE1headerFields.FieldByName("CUSTPO").SetValue("MY PO" + _CUSTID, false);
ARINVOICE1headerFields.FieldByName("IDSHIPNBR").SetValue("MY SHIP NUMBER" + _CUSTID, false);
ARINVOICE1header.Insert();
ARINVOICE1detail1.Read(false);
ARINVOICE1detail1.Read(false);
ARINVOICE1batch.Read(false);
ARINVOICE1header.RecordCreate(ViewRecordCreate.DelayKey);// 2
ARINVOICE1detail1.Cancel();

Parents Reply Children
  • 0 in reply to BOB2023

    Just to confirm - is the Invoice batch being created? I know that you're code is crashing when you're trying to populate the customer field but I want to confirm that the batch is being created.

    And when you debug, does:

    ARINVOICE1headerFields

    have what looks to be a valid assignment?

    And what about: ARINVOICE1headerFields.FieldByName("IDCUST")?

  • 0 in reply to Django

    When i go into the Sage software i know the first record is created or some sort of initial one is created because i pick it and opens up the Invoice, but there is no other data there.

    all objects are NOT null, i checked them all. 

    i checked the code 4 times, to see if i made a mix up, none there.