Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

The record in table Unlinked Attachment already exists. Identification fields and values: Id='{00000000-0000-0000-0000-000000000000}

(0) ShareShare
ReportReport
Posted on by 130

For creating sales orders attachment I used following request

https://api.businesscentral.dynamics.com/v2.0/<tenantID>/uat/api/v1.0/companies(companyID)/attachments

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 

  • Verified answer
    Dynamics Questions Profile Picture
    Dynamics Questions 130 on at
    RE: The record in table Unlinked Attachment already exists. Identification fields and values: Id='{00000000-0000-0000-0000-000000000000}

    Thank you a lot for your assistance, you helped me so much

  • Dynamics Questions Profile Picture
    Dynamics Questions 130 on at
    RE: The record in table Unlinked Attachment already exists. Identification fields and values: Id='{00000000-0000-0000-0000-000000000000}

    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 ?

  • Suggested answer
    Jeremy Vyska Profile Picture
    Jeremy Vyska 727 on at
    RE: The record in table Unlinked Attachment already exists. Identification fields and values: Id='{00000000-0000-0000-0000-000000000000}

    You are right to be confused, it's confusing.

    There is no built-in API for the FactBox "Attachments".

  • Dynamics Questions Profile Picture
    Dynamics Questions 130 on at
    RE: The record in table Unlinked Attachment already exists. Identification fields and values: Id='{00000000-0000-0000-0000-000000000000}

    Hi Jeremy Vyska 

    Thank you for detailed explanation.

    I checked this tab and my document is present 

    pastedimage1678359149207v2.png

    I need to clarify one moment - Is the only one approach how to add files programmatically to Business central ?

    To Incoming documents

     pastedimage1678359259220v3.png

    Or there is an ability to add documents to this tab 

    pastedimage1678359288024v4.png

  • Suggested answer
    Jeremy Vyska Profile Picture
    Jeremy Vyska 727 on at
    RE: The record in table Unlinked Attachment already exists. Identification fields and values: Id='{00000000-0000-0000-0000-000000000000}

    This is one of the challenges folks have.

    "Attachments" <> "Incoming Documents".

    pastedimage1678341363362v1.png

    After I run the Postman call above that creates the "attachment", even without uploading the /attachmentContent yet, I can verify the Incoming Document exists.

    pastedimage1678341564576v2.png

    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':

    pastedimage1678341671758v3.png

    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:

    pastedimage1678341836382v4.png

    Then on the Incoming Document screen, you should now be able to click on the file drilldown/link to open the 'attachment'.

  • Dynamics Questions Profile Picture
    Dynamics Questions 130 on at
    RE: The record in table Unlinked Attachment already exists. Identification fields and values: Id='{00000000-0000-0000-0000-000000000000}

    Hi Jeremy Vyska 

    Everything  is same as you have explained

    I got these fields

    image

    I copied mediaEditLink value and performed PATCH request with it as you described

    The request did not failed

    image

    but unfortunately the attachment is not present in the system, only Sales Order fields are present 

    image

  • Dynamics Questions Profile Picture
    Dynamics Questions 130 on at
    RE: The record in table Unlinked Attachment already exists. Identification fields and values: Id='{00000000-0000-0000-0000-000000000000}

    Everything as you have explained

    I got these fields

    pastedimage1678291503900v1.png

    I copied mediaEditLink value and performed request with it as you described

    The request did not failed

    pastedimage1678291625638v2.png

    but unfortunately the attachment is not present in the system, only Sales Order fields are present 

    pastedimage1678291877426v1.png

  • Jeremy Vyska Profile Picture
    Jeremy Vyska 727 on at
    RE: The record in table Unlinked Attachment already exists. Identification fields and values: Id='{00000000-0000-0000-0000-000000000000}

    Unexpected.   OK.

    This is an example of the POST call that should generate the 'attachment' (aka Incoming Document) entry, with an example response:

    pastedimage1678290479857v1.png

    The PATCH should then be against the URL described in the mediaEditLink.   Is the POST call returning the same JSON structure or something else?

  • Dynamics Questions Profile Picture
    Dynamics Questions 130 on at
    RE: The record in table Unlinked Attachment already exists. Identification fields and values: Id='{00000000-0000-0000-0000-000000000000}

    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 

    pastedimage1678289184879v1.png

  • Dynamics Questions Profile Picture
    Dynamics Questions 130 on at
    RE: The record in table Unlinked Attachment already exists. Identification fields and values: Id='{00000000-0000-0000-0000-000000000000}

    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 

    pastedimage1678289097967v1.png 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans