Get last inserted ID
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?
Pedro Magueija replied
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.
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.