cancel
Showing results for 
Search instead for 
Did you mean: 

Invalid Row in SetCurrentLine

rajesh_khater
Active Participant
0 Kudos

Hi,

I am adding a Service Type AP Invoice with 3 rows, and catching the FormDataEvent for Add event type.

I have written a test code to retrieve a UDF values in all the 3 rows.

When I try oInvLines.SetCurrentLine(1);

I get the Exception: Invalid row.

I have tried several times by duplicating an invoice, and getting same error. Tried searching in forum, and all threads suggest that SetCurrentLine should pass the Visual Row No. as the parameter, which is correct in this case.


void SBO_Application_FormDataEvent(ref SAPbouiCOM.BusinessObjectInfo BusinessObjectInfo, out bool BubbleEvent)

        {

            BubbleEvent = true;

            try

            {

                if (BusinessObjectInfo.FormTypeEx == "141"

                    && BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD

                    && BusinessObjectInfo.BeforeAction == false)

                {

                    if (BusinessObjectInfo.ActionSuccess)

                    {

                        string objectXml = BusinessObjectInfo.ObjectKey;

                        System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();

                        xmlDoc.LoadXml(objectXml);

                        string docKeyStr = xmlDoc.SelectSingleNode("DocumentParams/DocEntry").InnerText;

                        int docKey = Convert.ToInt32(docKeyStr);

                        SBO_Application.StatusBar.SetText("Invoice created with Key: " + docKey.ToString(), SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);

                        SAPbobsCOM.Documents oInvoice = null;

                        SAPbobsCOM.JournalEntries oJrnlEntry = null;

                        oInvoice = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);

                        if (oInvoice.GetByKey(docKey))

                        {

                            SAPbobsCOM.Document_Lines oInvLines = null;

                            oInvLines = oInvoice.Lines;

                            int noOfRows = oInvLines.Count;

                            SAPbobsCOM.BoDocumentTypes docType = oInvoice.DocType;

                            if (docType == SAPbobsCOM.BoDocumentTypes.dDocument_Service)

                            {

                                SBO_Application.StatusBar.SetText("Invoice Type: Service" + ", No. of Rows in Invoice: " + noOfRows.ToString(), SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);

                            }

                            else

                            {

                                SBO_Application.StatusBar.SetText("Invoice Type: Item" + ", No. of Rows in Invoice: " + noOfRows.ToString(), SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);

                            }

                            oInvLines.SetCurrentLine(0);

                            object fieldVal = oInvLines.UserFields.Fields.Item("U_ExpenseType").Value;

                            SBO_Application.StatusBar.SetText("Line 0: Expense Type: " + fieldVal.ToString(), SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);

                            oInvLines.SetCurrentLine(1);

                            fieldVal = oInvLines.UserFields.Fields.Item("U_ExpenseType").Value;

                            SBO_Application.StatusBar.SetText("Line 1: Expense Type: " + fieldVal.ToString(), SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);

                            oInvLines.SetCurrentLine(2);

                            fieldVal = oInvLines.UserFields.Fields.Item("U_ExpenseType").Value;

                            SBO_Application.StatusBar.SetText("Line 2: Expense Type: " + fieldVal.ToString(), SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);

                        }

                    }

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

I have checked in the database, that the Visorder and Linenum are correct:

Accepted Solutions (1)

Accepted Solutions (1)

rajesh_khater
Active Participant
0 Kudos

oh... I selected the wrong Business Object Type

In my code,

oInvoice = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);

should be:

oInvoice = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices);

The issue is solved !!

Answers (1)

Answers (1)

rajesh_khater
Active Participant
0 Kudos

I modified my code to print the no. of lines:

int noOfRows = oInvLines.Count;

Surprisingly, it is returning 1, even though there are 3 lines in the AP Invoice and 3 lines for the corresponding DocEntry in PCH1 table !

Is the behaviour different for Service Type AP Invoice?