Skip to Content
0

Need an example for create draft document thru DI API

Sep 13, 2017 at 03:44 AM

375

avatar image
Former Member

Dear All,

I need to create a draft document ( sales Invoice ), data shall be saved into table ODRF and DRF1, I had tried modify given sample code in SDK.

Now the question is : Suppose there are 10 items on the Invoice, after data insertion, there should be 10 new records in table DRF1, all with same document entry and line number ( ranging from 0 to 9 ), appreciated that if someone could provide me some sample codes, thank you !

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
ANKIT CHAUHAN
Sep 13, 2017 at 08:31 AM
0

Hi Scott,

You need to use it following way:

SAPbobsCOM.Documents oDocDraftSalesInvoice = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts);
oDocDraftSalesInvoice.DocObjectCode = SAPbobsCOM.BoObjectTypes.oInvoices;


//Setting up the data for Header


oDocDraftSalesInvoice.DocDueDate = DateTime.Today;
oDocDraftSalesInvoice.CardCode = CardCode;


//Setting up the data for Lines


oDocDraftSalesInvoice.Lines.ItemCode = ItemCode;
oDocDraftSalesInvoice.Lines.Quantity = 1;


// This will add the second line. You need to repeat this process for 10 lines.


oDocDraftSalesInvoice.Lines.Add();
oDocDraftSalesInvoice.Lines.ItemCode = ItemCode;
oDocDraftSalesInvoice.Lines.Quantity = 2;


//This will attempt to add the document.
int AddDraftSalesInvoice = oDocDraftSalesInvoice.Add();


if (AddDraftSalesInvoice != 0)
{
    MessageBox.Show(oCompany.GetLastErrorDescription());
}
else if (AddDraftSalesInvoice == 0)
{
    MessageBox.Show("Document added successfully!");
}

Hope it helps!

Kind regards,

ANKIT CHAUHAN

SAP SME Support

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member
Hi, Ankit Chauhan: Appreciate on your timely response, I got it !

If possible, would like to know something further -

People could generate more than 1 invoice at once, for example, 4 new invoice draft generated,

each contains 5, 4, 6, 3 detail items respectivelly ( saved to table DRF1 ), can you show me how to implement ?

( actually I got some duplicated items using while loop )

Thanks !!

Scott Hsu

0

Hi Scott,

You just need to repeat the above mentioned sample code in a loop.

Kind regards,

ANKIT CHAUHAN

SAP SME Support

0