Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Invalid Row in SetCurrentLine

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:

replied

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 !!

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question