Add attachment to a document which is in adding mode in SAP SDK

1.5k Views Asked by At

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?

1

There are 1 best solutions below

2
On BEST ANSWER

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 calling GetNewObjectKey on the company object. You can then use this key in the attachment update, finally committing the whole transaction (with EndTransaction).

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/