cancel
Showing results for 
Search instead for 
Did you mean: 

oCompany.GetNewObjectCode

Former Member
0 Kudos

Hi!

I need to use the oCompany.GetNewObjectCode method in the FormDataAddEvents (After Action), but the DocEntry remains equal to "" after the call of oCompany.GetNewObjectCode method. My code is the following:

Dim DocEntry As String = ""

oCompany.GetNewObjectCode(DocEntry)

Dim oInvoice As SAPbobsCOM.Documents = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)

oInvoice.GetByKey(DocEntry)

Help me! Thanks...

Accepted Solutions (1)

Accepted Solutions (1)

former_member201110
Active Contributor

Hi Gianluca,

The GetNewObjectCode method only works when the object has been added using the DI API and not when it's the user interface that has added the object.

There is a property of the BusinessObjectInfo that returns an XML string that includes the DocEntry of the document that has just been added. This property is only available when BeforeAction is false. To get the DocEntry value you can load the XML string in to a .NET XMLDocument object:


private void _sboApp_FormDataEvent(ref SAPbouiCOM.BusinessObjectInfo BusinessObjectInfo, out bool BubbleEvent)
{
    BubbleEvent = true;

    if (!BusinessObjectInfo.BeforeAction && BusinessObjectInfo.ActionSuccess)
    {
        // Document was added successfully so get the DocEntry
        int iDocEntry = GetDocEntryFromXML(BusinessObjectInfo.ObjectKey);
        // .........
        // ........
    }
}

private int GetDocEntryFromXML(string sXML)
{
    XmlDocument xDoc = new XmlDocument();

    xDoc.LoadXml(sXML);
    string sDocEntry = xDoc.SelectSingleNode("DocumentParams/DocEntry").InnerText;
    if (sDocEntry != "")
    {
        return Convert.ToInt32(sDocEntry);
    }
    else
    {
        return -1;
    }
}

Note that the XML returned by the BusinessObjectInfo.ObjectKey property is different for different object types (eg items, documents, business partners etc) so the above code will work for all document types but would fail for other objects that didn't have either the DocumentParams or DocEntry nodes in the XML.

Kind Regards,

Owen

former_member682029
Contributor
0 Kudos

hi

Some times I noticed that the XML also returns a blank string "". The XML returns fine for all marketing documents and all system form interfaces. But when using a UDO the XML is blank.

So I am using "GetNextSerialNumber()" method.

Public Function GetNextSerialNumber( _
   ByVal series As String, _
   Optional ByVal ObjectType As String = "" _
) As Long

Parameters

series

Specifies the series for which you want to get the next number.

ObjectType

A string specifying the object type for which you want to get the serial number.

Remarks

Relevant only to UDOs of type Document initiated with the Manage Series service.

You can use this method to automatically set or display the document number on your form when the form is connected to a user-defined object of type Document.

In SAP Business One document objects, such as Invoice or Purchase Order are typically automatically numbered according to a pre-defined series associated with this document.

Anoop

Answers (1)

Answers (1)

Former Member
0 Kudos

Expect you need the docentry of created document. Try it as

Dim ooform As SAPbouiCOM.Form

ooform = SBO_Application.Forms.Item(BusinessObjectInfo.FormUID)

docentry = Trim(ooform.DataSources.DBDataSources.Item(0).GetValue("DocEntry", 0))

oInvoice.GetByKey(DocEntry)