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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Adding a document to a row programmatically

(0) ShareShare
ReportReport
Posted on by

Hello,using the following code,i'm trying to add a document to a table; however i can not see anything added in document management.The code also doesn't give any errors, any ideas how to resolve it ?

    DocuRef docuRef;
    DocuActionArchive archive;
    
    erm_OperationInstructions oprinst;
    

    Name _name = "C:\\test.txt";
    
    
    select firstOnly * from oprinst where oprinst.OperationId == 'OP0001002';
    
    
    try
    {
        ttsBegin;
        
        docuRef.clear();
        docuRef.RefRecId = oprinst.RecId;
        docuRef.RefTableId = tableNum(erm_OperationInstructions);
        docuRef.RefCompanyId = curext();
        docuRef.Name = "testfile";
        docuRef.TypeId = 'FILE';
        docuRef.insert();
        archive = new DocuActionArchive();
        archive.add(docuRef, _name);          
        
        ttsCommit;
    }
    catch(Exception::Error)
    {
        info(strfmt("%1",Exception::Error));

    }

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Have you looked into DocuRef table and verify whether the records are created there ?

  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at

    Set a breakpoint in the DocuActionArchive\add() method and follow the execution path.  Depending on how your Document type of FILE is setup in your system, many things could be going wrong.  Some of the errors that can occur would not be caught by a catch(Exception::Error) either, so there might not be any visible results.  The UI has a nasty habit of not surfacing CLR or COM errors, for example, like it does X++ errors.

  • Community Member Profile Picture
    on at

    Hey all,with the following code,it works:

                ttsbegin;
                docuref.TypeId = "TYPEIV";
                docuref.Name = _name;
                docuref.Notes = docuRef.Notes;
                docuRef.Restriction = DocuRestriction::Internal;
                docuref.RefCompanyId = curext();
                docuref.RefTableId = tablenum(OperationInstructions);
                docuref.RefRecId = oprinst.RecId;
                docuref.insert();
    
    
                docuvalue.initValue();
                docuvalue.insert(); docuref.ValueRecId = docuvalue.RecId;
                docuref.update();
                docuvaluerecid = docuvalue.RecId;
    
                select forupdate docuvalue where docuvalue.recid == docuvaluerecid;
    
                docuvalue = docuvalue::writeDocuValue(docuref,_name+".xlsx");
                ttscommit;


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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Sagar Suman Profile Picture

Sagar Suman 2 Super User 2026 Season 1

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans