web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

how to update attachment with new ID

(5) ShareShare
ReportReport
Posted on by 155

Hi,

I’m updating the ID on the custom page header. When the ID is successfully updated, the sub-link remains intact because the "ID" is automatically updated as well. However, this does not happen with attachments. When the ID is changed, the attached files are removed from the page. When I revert the ID to its previous value, the attachment reappears, because the "ID" isn't being updated in the "Document Attached table".

Question: How can I update the ID on the header page without causing the attachments to be removed?

Thanks.

 
 
after update
 
 
 
 
I have the same question (0)
  • Suggested answer
    Jainam M. Kothari Profile Picture
    15,639 Super User 2025 Season 2 on at
    Hello,
     

    To update the ID on the header page without causing the attachments to be removed in Business Central, you need to ensure that the ID is also updated in the "Document Attached" table. Here are the steps you can follow:

    1. Retrieve the current attachments: Before updating the ID, retrieve the current attachments associated with the old ID.
    2. Update the ID in the "Document Attached" table: After updating the ID on the header page, update the ID in the "Document Attached" table to match the new ID.
    3. Reattach the documents: If necessary, reattach the documents to the new ID.

    You can use the Business Central API to update the document attachments. Here is an example of how to update the document attachment object:

    PATCH https://{businesscentralPrefix}/api/v2.0/companies({companyId})/documentAttachments({attachmentId})
    Content-type: application/json
    {
      "id": "{newId}",
      "fileName": "{fileName}",
      "attachmentContent": "{attachmentContent}"
    }
    

    Make sure to replace {businesscentralPrefix}, {companyId}, {attachmentId}, {newId}, {fileName}, and {attachmentContent} with the appropriate values.

    This approach ensures that the attachments remain linked to the updated ID and are not removed from the page.

  • Gerardo Rentería García Profile Picture
    25,230 Most Valuable Professional on at
  • Suggested answer
    Ramesh Kumar Profile Picture
    7,527 Super User 2025 Season 2 on at
    You need to update the code to include the new attachment ID and Modify the ID Update Logic:
    You can modify the logic where the ID update occurs, so that it first updates the attachment records before updating the header ID
     
    begin
    // First, update the Document Attached table
    if DocumentAttachedRec.Get(OldID) then begin
    DocumentAttachedRec."Header ID" := NewID; // Update the ID in the Document Attached table
    DocumentAttachedRec.Modify();
    end;

    // Then, update the header ID
    HeaderRec."ID" := NewID;
    HeaderRec.Modify();
  • Suggested answer
    YUN ZHU Profile Picture
    95,729 Super User 2025 Season 2 on at
    In short, you need to rename the primary key of table 1173 "Document Attachment" in the rename trigger of your new table.
     
    Hope this helps.
    Thanks.
    ZHU
  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at
    The document attachments are linked based on the record values, so it stores the record primary key values in the table to link it, if you update ID which looks you are renaming the primary key or one of the key values which is specified in the document attachment in that case you need to access Document Attachment and update that.
     
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,441 Super User 2025 Season 2 on at
  • Vahid Ghafarpour Profile Picture
    12,151 Super User 2025 Season 2 on at
    If any of the responses helped resolve your issue, please take a moment to mark the best answer. This helps others in the community quickly find solutions to similar problems.

    To do this, simply click the "Does this answer your question?" button on the most helpful response and like the helpful posts. If your issue is still unresolved, feel free to provide more details so the community can assist further!

    Thanks for being an active part of the Dynamics 365 Community! 😊

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,468

#2
YUN ZHU Profile Picture

YUN ZHU 923 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 607

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans