on 05-05-2016 5:39 PM
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
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
User | Count |
---|---|
100 | |
12 | |
11 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.