How to Open Word document through Job in AX 2012


Description:-

If you want to Open Word file through Job in Ax you can user COM variant and open word file through Job. Using COM variant or dialog Field, Word Documents through we can achieve this functionality in ax 2012.

static void OpenWordTemplate()
{
    COM                     wordApp;
    dialog                  d;
    Dialog                  dialog = new dialog();
    dialogField             dialogFilename;
    COM                     wordDocuments;
    FileName                fileName;
    
    wordApp = new COM("word.application");
    wordDocuments = wordApp.Documents();

    d = new dialog();
    d.caption("select a file");
    //add a field where you select your file in a specific path
    dialogFilename = d.addField(extendedTypeStr(FilenameOpen),"File Name");
    d.run();//execute dialog
    
    if(d.closedOk())
    {
        filename = dialogFileName.value();//return path file value
    }
    
    try
    {
        wordDocuments.Open(fileName);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }
    wordApp.visible(true);
}

Run your Job after File Dialog will open select File from that Dialog and Click ‘OK’ to open that File through Job in ax 2012.

Related Posts

Previous
Next Post »