Skip to Content
0
Dec 22, 2022 at 05:15 AM

Get DocNum of last approved invoice added in addon

27 Views

I have an addon running and I am trying to get the last DocNum of an approved invoice in SAP B1.

For example if 2 invoices have been approved, the DocNums show to be the same once approved but before that are added as documents.

I use the query below to fetch the last DocNum:

rs.DoQuery("SELECT MAX(T0.\"DocNum\") AS \"DocNum\" FROM OINV T0 INNER JOIN NNM1 T1 ON T0.\"Series\" = T1.\"Series\" WHERE T0.\"BPLId\" = '" + branch + "'");
rs.MoveFirst();

The problem with this is that it returns the same document number for the 2 invoices that I add back to back.

Is there a way to get the just added document in SDK. Invoices are not being added through the addon, they are added through the regular add button but I need to catch the proper Document Number just added.