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 :
Microsoft Dynamics AX (Archived)

Creating word documents from X++

(0) ShareShare
ReportReport
Posted on by 165

Does anyone have experience creating word documents from code and inserting relevant DAX data?  We are trying to spit out letters through a class as we process info.  I am currently looking at the docuAction and extended classes, but seem to be getting held up on the parameters to send.

 We do not necessarily need the doc stored on the record, our main goal is the generation and saving of the file.

 Any help is appreciated.

 Thanks

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

      Hi,

    as you probably know, Document handling allows you to specify a word template and map table fields to bookmarks in the template (Basic > Setup > Document management > Document types > Options).

    Docu* classes use that logic and therefore they require DocuRef record. The core is something like this:

        DocuRef docuRef = DocuRef::findRecId(5637146847);
    DocuAction action = DocuAction::newDocuType(DocuRef.docuType());
    Args args = new Args();
    ;

    args.record(docuRef);
    args.parmEnumType(enumNum(DocuCode));
    args.parmEnum(DocuCode::Add);

    action.findDocuTable(docuRef.RefTableId);
    action.run(args);

     

    Another possibility is to use COM (example) or .NET classes.

  • DaxDev Profile Picture
    165 on at

    Martin -

     Thanks for you reply.  I went with nearly that same aproach and used both Docu classes and the Com classes to create the word document and store it with document handling.  Took a bit to get the args right for the docu class since I was doing it through code but it worked.

     Your response and time is greatly appreciated.

  • Rajdip Das Profile Picture
    3,333 on at

    You can also check the following jobs...

    static void Raj_ToWord(Args _args)
    {
        COM wordApplication;
        COM wordDocuments;
        COM wordDocument;
        COM wordRange;
        ;

        wordApplication = new COM("word.application");
        wordApplication.visible(TRUE);
        wordDocuments = wordApplication.Documents();
        wordDocument = wordDocuments.add();
        wordDocument.saveas("c:\\TestDoc.doc");
        wordDocument.activate();
        wordRange = wordDocument.range(0,0);
        wordRange.insertafter("Rajdip Das");

        wordRange.italic(true);
        wordDocument.save();
     //   wordDocument.close();
     //   wordApplication.quit();
    }

     

    happy daxing :)

  • Bradley Burden Profile Picture
    10 on at

    We use the standard document handling to create word documens for CRM quotes. there are some significant formatiing limitations because the document handling inserts all records from the quoet line into the SAME row of the word table where the bookmarks are. I want to include a new field similar to the "Hard Return" option but his will be "Tab Option" so I can send a tab on the last field in the row to create a new row in the word table. can Someone point me in the direction to where the "Hard Return" code is executed?

     

    thanks

  • Bradley Burden Profile Picture
    10 on at

    I found the code in Class DocuActionCOM_word:

    boolean insertHardLineBreak()
    {
        coMrange.insertAfter(num2char(13));
        coMrange.insertAfter(num2char(9)); //my test here to add tab
        return true;
    }

     

    it did not acheive what I wanted, it just added a tab at the end of the data in the cell rather than creating a new row in the tale.

    So if anyone knows how to get each record into a new row of the word table it would be much appreciated. At the moment it takes quite a while for the users to manually reformat the document.

  • Community Member Profile Picture
    on at

    I have only tried to creat Word documents using C#. I think you'd better choose some fine Word processing SDK to help you with your work.  It can be easy in the generation and saving of the file. You can google it and check some free trial package first if possible. I hope you success. Good luck.

    Best regards,

    Arron

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans