For creating sales orders attachment I used following request
Body:
{ “parentId”: “5a086bc7-195f-eb11-89f9-0022481ab2d5”, “fileName”: “Example.pdf”}
At first time it worked and generated Id for attachment, but my PATCH request was failed
PATCH businesscentralPrefix/companies({companyId})/attachments(parentId={parentId},id={attachmentId})/content
I tried to do first request again as I did not saved parentId and now it throws such error : "{\"error\":{\"code\":\"Internal_EntityWithSameKeyExists\",\"message\":\"The record in table Unlinked Attachment already exists. Identification fields and values: Id='{00000000-0000-0000-0000-000000000000}' CorrelationId: e6964edd-e341-4da2-804d-534c1ea681e3.\"}}"
It was advised to retrieve the parent Id from the first successful attachment creation and use that parent Id in the PATCH request instead of creating a new one, but how to retrieve that parentid ? what request should be used ?
Thanks in advance
Thank you a lot for your assistance, you helped me so much
Thank you
I need to do same for purchaseInvoices and salesInvoices, type values for them will be "Purchase Invoice" and "Sales Invoice" correspondingly, right ? For implementing attachment for these entities everything will remain same, right ?
You are right to be confused, it's confusing.
There is no built-in API for the FactBox "Attachments".
Hi Jeremy Vyska
Thank you for detailed explanation.
I checked this tab and my document is present
I need to clarify one moment - Is the only one approach how to add files programmatically to Business central ?
To Incoming documents
Or there is an ability to add documents to this tab
This is one of the challenges folks have.
"Attachments" <> "Incoming Documents".
After I run the Postman call above that creates the "attachment", even without uploading the /attachmentContent yet, I can verify the Incoming Document exists.
In the Sales Order, I know an Incoming Document is attached because the View Incoming Document becomes enabled as an action. If I select that action, I'll find the 'incoming document record':
However, since I haven't yet PATCH called to the /attachmentContent endpoint, when I click on the BCLogo.png drilldown/link, it will do nothing, as there is no file attached.
Now, with that "attachment" id (incoming document id), when do the PATCH call, I'll know it worked because I get the "204 No Content" response:
Then on the Incoming Document screen, you should now be able to click on the file drilldown/link to open the 'attachment'.
Hi Jeremy Vyska
Everything is same as you have explained
I got these fields
I copied mediaEditLink value and performed PATCH request with it as you described
The request did not failed
but unfortunately the attachment is not present in the system, only Sales Order fields are present
Everything as you have explained
I got these fields
I copied mediaEditLink value and performed request with it as you described
The request did not failed
but unfortunately the attachment is not present in the system, only Sales Order fields are present
Unexpected. OK.
This is an example of the POST call that should generate the 'attachment' (aka Incoming Document) entry, with an example response:
The PATCH should then be against the URL described in the mediaEditLink. Is the POST call returning the same JSON structure or something else?
Sorry I did not understand where to check View Incoming Document
After first step I get parent id, In this object there is no View Incoming Document field
Sorry I did not understand where to check View Incoming Document
After first step I get parent id, In this object there is no View Incoming Document field
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,113 Super User 2024 Season 2
Martin Dráb 229,918 Most Valuable Professional
nmaenpaa 101,156