cancel
Showing results for 
Search instead for 
Did you mean: 

Error creating Down Payment Invoice

Former Member
0 Kudos

I have worked on the assumption that my source order data would have the same number of lines for both Sales Order and Down Payment Invoice. I'm now guessing that when I use a BOM Item the DI-API automatically adds the component lines to the Sales Order.

To try and correct the mismatch in lines, after creating the Sales Order I have extracted the SalesOrder.Lines.Count value (less 1) and used this to iterate the Down Payment Invoice lines, as below:

DOC = Company.GetBusinessObject(BoObjectTypes.oDownPayments)

For intLoop As Integer = 0 To intSalesOrderLinesCount

   With DOC.Lines

      If intLoop > 0 Then

         .Add()

      End If

      .BaseEntry = lngDocEntry (fetched from generated Sales Order)

      .BaseType = BoObjectTypes.oOrders

      .BaseLine = intLoop

   End With

Next

Unfortunately I still seem to get the same error. Am I missing something more with BOM items in Sales Orders and Down Payment Invoices?

Error is -2010 Bad Data Source Offset

Accepted Solutions (1)

Accepted Solutions (1)

former_member185682
Active Contributor
0 Kudos

Hi David,

Did you try use:

For intLoop As Integer = 0 To intSalesOrderLinesCount - 1


Hope it helps.


Best regards,

Diego Lother


View Diego Lother's profile on LinkedIn

Former Member
0 Kudos

Hi Diego,

Yes, when I fetch the value since I have no other use for the count

intSalesOrderLinesCount = SalesOrder.Lines.Count - 1


I do think however that I may not have corrected adding an extra line for shipping carriage charges, unfortunately I've been diverted onto a hotfix for now so will get back to it asap.


Does the method I've used seem correct?



former_member185682
Active Contributor
0 Kudos

Hi David,

I created your scenario and I can see that when you use a BOM Item, just copy the line that have the father, or ignore the lines that are ingredients.

A sample:


                oCompany.StartTransaction();

                #region create order

                Documents oOrder = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);

                oOrder.CardCode = "C20000";

                oOrder.DocDueDate = DateTime.Now;

                oOrder.Lines.ItemCode = "CJ001"; //A BOM Item

                oOrder.Lines.Quantity = 1;

                int oOrderDocEntry = 0;

                if (oOrder.Add() != 0)

                {

                    MessageBox.Show(oCompany.GetLastErrorDescription());

                    return;

                }

                else

                {

                    oOrderDocEntry = Convert.ToInt32(oCompany.GetNewObjectKey());

                    MessageBox.Show("Order [" + oOrderDocEntry + "] created!");

                }

                #endregion

               

                #region create a downpayment based in a order

                oOrder = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);

                if (oOrder.GetByKey(oOrderDocEntry))

                {

                    Documents oDownPayment = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDownPayments);

                    oDownPayment.CardCode = oOrder.CardCode;

                    oDownPayment.DocDueDate = oOrder.DocDueDate;

                    oDownPayment.DownPaymentType = DownPaymentTypeEnum.dptInvoice;

                    for (int i = 0; i < oOrder.Lines.Count; i++)

                    {

                        oOrder.Lines.SetCurrentLine(i);

                        if (oDownPayment.Lines.BaseEntry != 0) //you can use other validation to open a newline

                            oDownPayment.Lines.Add();

                        if (oOrder.Lines.TreeType != BoItemTreeTypes.iIngredient) //Just copy itens that is not an ingredient.

                        {

                            oDownPayment.Lines.BaseType = (int)SAPbobsCOM.BoObjectTypes.oOrders;

                            oDownPayment.Lines.BaseEntry = oOrderDocEntry;

                            oDownPayment.Lines.BaseLine = i;

                        }

                    }

                    if (oDownPayment.Add() != 0)

                    {

                        MessageBox.Show(oCompany.GetLastErrorDescription());

                        return;

                    }

                    else

                    {

                        MessageBox.Show("DownPayment [" + oCompany.GetNewObjectKey() + "] created!");

                    }

                }

                #endregion

                if (oCompany.InTransaction)

                    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

Works for me, SAP B1 9.1 PL 11

Hope it helps.


Best regards,

Diego Lother


View Diego Lother's profile on LinkedIn

Former Member
0 Kudos

Diego,

This will be a great help thank you. Out of interest, how to do insert code blocks in the forum editor?

Dave

Former Member
0 Kudos

Hi Diego,

Got it fixed thanks.

These two lines being what I wasn't doing.

oOrder.Lines.SetCurrentLine(i)

oOrder.Lines.TreeType != BoItemTreeTypes.iIngredient

former_member185682
Active Contributor
0 Kudos

Hi David,

To insert code blocks you need select Use Advanced editor.

Select your type of code.

And then the code block will be appears.


Best regards,

Diego Lother


View Diego Lother's profile on LinkedIn

Answers (0)