I have developed an addon which adds scanned images to the invoice. If an invoice is added I have no problem, if it's in adding mode I can't allocate it because I don't have a DocEntry value which I need to pass.
Is it possible to add an attachment to a sales document in SDK which is in adding mode?
If you're using DI-API:
Wrap the document creation and attaching the file to the document within a single transaction (see the SDK documentation on the
StartTransaction
method on the company object). After adding the document (still within the transaction) get the new DocEntry back from the first update by callingGetNewObjectKey
on the company object. You can then use this key in the attachment update, finally committing the whole transaction (withEndTransaction
).If you're using Service Layer:
You can't do it in one transaction without writing some server-side Javascript to call. See https://blogs.sap.com/2017/09/01/implementing-service-layers-script-engine/