Skip to Content

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

Get last inserted ID

Hello everyone,

Using SAP B1 9.1 and  working on Sales Order form trying to figure something out. When a user clicks the ADD button, data is successfully inserted to DB. Now, back in Visual Studio, in Button_ClickBefore event I'm trying to "catch" the inserted ID of the sales order so I can use it elsewhere. I know I can use GetNewObjectCode, but only if I insert data using DI.

Since this is the "default" insert operation, the above sub won't return anything. So, what's the logic behind all this? How do I get the ID if it's not being inserted through DI?

Thank you

Former Member

Hi Arnes,

Catch the FORM_DATA_ADD event and the argument contains the key that was inserted in xml format:

pVal.ObjectKey where pVal is a BusinessObjectInfo.

From the SDK Help Center:


The unique ID in XML format of the business object on which the event occurred.

Property type

Read-only property


Visual Basic

Public Property ObjectKey() As String


The property returns an empty string in the following cases:

Business objects that are not exposed in the DI API.

In the before notification of an Add action (et_FORM_DATA_ADD).

In the before notification of a Load action (et_FORM_DATA_LOAD) triggered by a Find operation.

Best regards,

Pedro Magueija

View Pedro Magueija's profile on LinkedIn

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