cancel
Showing results for 
Search instead for 
Did you mean: 

Document_LinesAdditionalExpenses on alternative item line

rico_hengst
Discoverer
0 Kudos

Hi experts,

on a sales quotation document i calculate additional expenses for each line in the FORM_DATA_ADD event.


     ......

     oExpenses = oLines.Expenses;

     oExpenses.SetCurrentLine(0);

     oExpenses.GroupCode = 0;

     oExpenses.ExpenseCode = dataList.Data.ExpnsCode;

     oExpenses.LineTotal = dataList.Data.LineTotal;

     oExpenses.Add();

     .....

     ret = oDocument.Update();

     ....

This works fine on regular item lines but if there is alternative item line i got the error -5002 "There is a difference between the document total and its components.  [OQUT.DocTotal][line: 0]"

I don't set neither the oDocument.DocTotal nor the oDocument.oLines.LineTotal.

I tried several things, switch the alternative line to a regular line, update the document, switch back, update again - but nothing works.

Is this a bug or am I missing something?

Regards,

Rico

Accepted Solutions (0)

Answers (1)

Answers (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Rico,

Can you please be more specific?

Can you please help to provide the steps to reproduce this issue?

Kind regards,

ANKIT CHAUHAN

SAP Business One Global Support

rico_hengst
Discoverer
0 Kudos

Hi Ankit,

i will try it.

I catch the FORM_DATA_ADD event, which works fine.


                    if (businessObjectInfo.BeforeAction == false && businessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD)

                    {

                        string docEntry = oForm.DataSources.DBDataSources.Item("OQUT").GetValue("DocEntry", 0);

                        if (!string.IsNullOrEmpty(docEntry))

                            AddDataAfter(businessObjectInfo.FormTypeEx, docEntry);

                    }

In the AddDataAfter method I do some calulation (highly simplified form).


        private void AddDataAfter(string formTypeEx, string docEntry)

        {

            SAPbobsCOM.Documents oDocument = null;

            SAPbobsCOM.Document_Lines oLines = null;

            SAPbobsCOM.Document_LinesAdditionalExpenses oExpenses = null;

            oDocument = oConnection.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oQuotations);

            oDocument.GetByKey(Convert.ToInt32(docEntry));

            oLines = oDocument.Lines;

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

            {

                oLines.SetCurrentLine(i);

                oExpenses = oLines.Expenses;

                //Fracht 1

                oExpenses.SetCurrentLine(0);

                oExpenses.GroupCode = 0;

                oExpenses.ExpenseCode = 37;

                oExpenses.LineTotal = (100 + i);

                oExpenses.Add();

            }

            int ret = oDocument.Update();

            if (ret != 0)

                SBO_Application.SetStatusBarMessage(oConnection.oCompany.GetLastErrorDescription());

        }

This works fine for regular item lines (Screenshot 1) but if there is one alternative line the update doesn't work (Screenshot 2).

I forgot SAP-Version: SAP Business One 9.1 (9.10.190) PL: 09  (32-bit)

Kind regards,

Rico