Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Adding a document to a row programmatically

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Adding a document to a row programmatically

    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;


  • Suggested answer
    Brandon Wiese Profile Picture
    Brandon Wiese 17,788 on at
    RE: Adding a document to a row programmatically

    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
    Community Member Microsoft Employee on at
    RE: Adding a document to a row programmatically

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

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