Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi and Accpac 1

Status
Not open for further replies.

KE50

Programmer
Jul 3, 2012
10
What could i be doing wrong with the code below;

Code:
  //Create the header
  InvHeader.RecordCreate(2);
  InvHeader.Cancel;
  InvHeader.Fields.Item('CNTBTCH').Value := InvBatch.Fields.Item('CNTBTCH').value;
  InvHeader.Fields.Item('CNTITEM').PutWithoutVerification('1');
  InvHeader.Fields.Item('IDCUST').Value := TempHeader.IDCust;
  InvHeader.Fields.Item('PROCESSCMD').PutWithoutVerification('4');
  InvHeader.Fields.Item('INVCDESC').PutWithoutVerification(TempHeader.InvcDesc);
  InvHeader.Process;

The error appears on the "IDCust" line
 
Are you early or late binding? I'm guessing late.

What is the error that you're getting? Have you wrapped that code in a try..except? What version of Accpac? And what does rvSpy show?
 
It looks like Accpac is complaining about the tax group associated with that customer.

Try creating a new invoice in Accpac with that same customer and see what message appears.
 
Adding an invoice manually for the customer goes on without an issue
 
Changing the company parameters to another company and still the code fails at this point
 
Might it be anything to do with the compose done
 
Quite possibly. If the compositions aren't right that can cause a problem. Show us your code.
 
Code:
 //Make relations for the connections (Compose)
  InvBatch.Compose(InvHeader);

  //Header
  VarClear(ViewArray);
  ViewArray := varArrayof([InvBatch, InvHeader, InvDetail, InvSchedule]);
  InvHeader.Compose(CSGetOleVariant(ViewArray, 1));

  //Detail
  VarClear(ViewArray);
  ViewArray := varArrayof([InvBatch, InvHeader, InvDetail, InvSchedule]);
  InvDetail.Compose(CSGetOleVariant(ViewArray, 2));

  //Schedule
  VarClear(ViewArray);
  ViewArray := varArrayof([InvHeader, InvSchedule]);
  InvDetail.Compose(CSGetOleVariant(ViewArray, 1));

  //Create and label the Batch
  InvBatch.RecordCreate(1);
  InvBatch.Read;
  InvBatch.Fields.Item('BTCHDESC').PutWithoutVerification('This is a test batch');
  InvBatch.Update;
  InvBatch.Read;

  //Create the header
  InvHeader.RecordCreate(2);
  InvHeader.Cancel;
  InvHeader.Fields.Item('CNTBTCH').Value := InvBatch.Fields.Item('CNTBTCH').value;
  InvHeader.Fields.Item('CNTITEM').PutWithoutVerification('1');
  InvHeader.Fields.Item('IDCUST').Value := TempHeader.IDCust;
  InvHeader.Fields.Item('PROCESSCMD').PutWithoutVerification('4');
  InvHeader.Fields.Item('INVCDESC').PutWithoutVerification(TempHeader.InvcDesc);
  InvHeader.Process;

The other bit during compose;

Code:
//The function for producing an OleVariant array takes an array of variants and the index of the view in the array being assigned to
//The function then loops through the Views array adding every item in the array to the ole variants array apart from the item being assigned to
Function CSGetOleVariant(var ViewArray : array of variant; AssigningToIndex : integer) : oleVariant;
var
  OleArray : oleVariant;
  i, j : integer;
Begin
  j := 0;
  OleArray := varArrayCreate([0, Length(ViewArray) - 1], varVariant);
  for i := 0 to Length(ViewArray) - 1 do
    Begin
      if i <> AssigningToIndex then
        OleArray[j] := ViewArray[i];
      inc(j);
    End;
  Result := OleArray;
End;
 
Examine the Session.Errors object when you get the error.
 
The compositions look wrong. No mention of optional fields. This is what I use. I've written some higher level objects to wrap around views and to wrap around the AR Invoice Batch as a whole so the code isn't exactly runnable as shown. But you can see how my compositions look.
Code:
      va := VarArrayCreate([0,0],varVariant);
      va[0] := ARIHeader.View;
      ARIBatch.View.Compose(va);


      va := VarArrayCreate([0,3],varVariant);
      va[0] := ARIBatch.View;
      va[1] := ARIDetail.View;
      va[2] := ARIPaymentSch.View;
      va[3] := ARIHeaderOF.View;
      ARIHeader.View.Compose(va);


      va := VarArrayCreate([0,2],varVariant);
      va[0] := ARIHeader.View;
      va[1] := ARIBatch.View;
      va[2] := ARIDetailOF.View;
      ARIDetail.View.Compose(va);

      va := VarArrayCreate([0,0],varVariant);
      va[0] := ARIHeader.View;
      ARIPaymentSch.View.Compose(va);

      va := VarArrayCreate([0,0],varVariant);
      va[0] := ARIHeader.View;
      ARIHeaderOF.View.Compose(va);

      va := VarArrayCreate([0,0],varVariant);
      va[0] := ARIDetail.View;
      ARIDetailOF.View.Compose(va);
 
Also - remove these extra lines. And confirm that VIEW_RECORD_CREATE_NOINSERT=2.

InvHeader.RecordCreate(2);
InvHeader.Cancel;
InvHeader.Fields.Item('CNTBTCH').Value := InvBatch.Fields.Item('CNTBTCH').value;
InvHeader.Fields.Item('CNTITEM').PutWithoutVerification('1');

InvHeader.Fields.Item('IDCUST').Value := TempHeader.IDCust;
 
Made the following changes;

1. Added the Invoice header optional field - View AR0402,

2. Added the Invoice detail optional field - View AR0401,

3. Added the try except and a function for returning the error message

But it still fails on the setting of IDCUST,

Incase the customer value being passed is blank, the error is 'Invalid input, the customer number cannot be blank' but when the customer number exists, the error is just blank

Please anyone with a clue how to sort out this???
 
I suspect that your compositions are still off. Repost what you have.
 
Code:
  //Make relations for the connections (Compose)
  InvBatch.Compose(InvHeader);

  //Header
  VarClear(ViewArray);
  ViewArray := varArrayof([InvBatch, InvHeader, InvDetail, InvSchedule, InvOptFld]);
  InvHeader.Compose(CSGetOleVariant(ViewArray, 1));

  //Detail
  VarClear(ViewArray);
  ViewArray := varArrayof([InvBatch, InvHeader, InvDetail, InvDetailOptFld]);
  InvDetail.Compose(CSGetOleVariant(ViewArray, 2));

  //Schedule
  VarClear(ViewArray);
  ViewArray := varArrayof([InvHeader, InvSchedule]);
  InvDetail.Compose(CSGetOleVariant(ViewArray, 1));

  //Invoice Optional Field
  VarClear(ViewArray);
  ViewArray := varArrayof([InvHeader, InvOptFld]);
  InvOptFld.Compose(CSGetOleVariant(ViewArray, 1));

  //Invoice Optional Field Detail
  VarClear(ViewArray);
  ViewArray := varArrayof([InvDetail, InvDetailOptFld]);
  InvDetailOptFld.Compose(CSGetOleVariant(ViewArray, 1));

  //Create and label the Batch
  InvBatch.RecordCreate(1);
  InvBatch.Read;
  InvBatch.Fields.Item('BTCHDESC').PutWithoutVerification('This is a test batch');
  InvBatch.Update;
  InvBatch.Read;

  try
    //Create the header
    InvHeader.RecordCreate(0);
    //The customer assigned does not exist and the error comes out as such
    InvHeader.Fields.Item('IDCUST').Value := '322';
    InvHeader.Fields.Item('PROCESSCMD').PutWithoutVerification('4');
    InvHeader.Fields.Item('INVCDESC').PutWithoutVerification(TempHeader.InvcDesc);
    InvHeader.Process;
  except
    CSShowErrors(AccObject);
  End;
 
Your schedule composition is composing the wrong view:
Code:
//Schedule
  VarClear(ViewArray);
  ViewArray := varArrayof([InvHeader, InvSchedule]);
  [s]InvDetail[/s]InvSchedule.Compose(CSGetOleVariant(ViewArray, 1));

See if that helps.
 
Nice catch, but still it gives an error and the Accpac Session Error is blank if the customer account exists.

A check on the site showed this; thread631-1212433 i think it is of a similar issue but i cannot tell how it was resolved

 
Hello DjangMan,

Thanks for all the input, the error was the composition, the function for generating must not have been working. Ended up using the sample you provided above

Again Thanks :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top