on 03-14-2015 8:05 AM
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:
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 !!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
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.