AX 2009, AX 2012, Development, Dynamics AX, Uncategorized

How to send a file to the printer in dynamics AX

How to send a file to the printer in dynamics AX

Following Job demonstrates on how to send a file from the file system to the locally connected printer( printer physically can be network or local but it should be added to the client and its name should be visible in the control panel–> devices and printers)

static void sendToPrinter(Args _args)
{
PrintJobSettings printJobSettings = new PrintJobSettings();
Dialog dialog = new Dialog();
DialogField dialogFileName;
str CoreLabelExe;
str CoreLabelParm;
;
// initiallize printer with the printer name. This initiallization automatically
// gets dll file details and port details.
printJobSettings = new PrintJobSettings();
printJobSettings.SetTarget(PrintMedium::Printer);
printJobSettings.deviceName(‘Microsoft XPS Document Writer’);
dialogFilename = dialog.addField(typeid(FilenameOpen));
if (dialog.run())
{
// finding executable DLL
CoreLabelExe = WinAPI::findExecutable(dialogFileName.value());
// Create Shell command parameter
CoreLabelParm = strFmt(‘ /PT “%1” “%2” “%3” “%4″‘,
dialogFileName.value(),
printJobSettings.printerPrinterName(),
printJobSettings.printerDriverName(),
printJobSettings.printerPortName());
// run dll on the shel with parameter
winAPI::shellExecute(CoreLabelExe, CoreLabelParm);
}
}

Standard
AX 2012, Development, Dynamics AX

How to Save SysLastValues on the form

you may find some instances where you want to save some additional data on the form w.r.to a user. Following example shows how you can implement this coding pattern to save last values on the form.

For any specific Implementation related queries shoot your questions at lokesh_kant@hotmail.com

  1. Identify the list of┬ávariables┬áthat you want to save with user’s Usage data.
  2. Implement following code
    public class FormRun extends ObjectRun{

    str x;

    #define.CurrentVersion(1)

    #localmacro.CurrentList

    x

    #endmacro

    }

    public void initParmDefault(){

    if(!x)

    x= “DEFAULT”;

    }

    public dataAreaId lastValueDataAreaId(){

    return curext();

    }

    public userId lastValueUserId(){

    return curuserid();

    }

    public UtilElementType lastValueType(){

    return UtilElementType::Form;

    }

    public identifiername lastValueElementName(){return this.name();}
    public identifiername lastValueDesignName(){return element.args().menuItemName();}
    public boolean unpack(container packedClass){int version = RunBase::getVersion(packedClass);;switch (version){case #CurrentVersion:[version,#CurrentList] = packedClass;

    return true;

    default:

    return false;

    }

    return false;

    }

    public void init(){super();// xctrl.text(“DEFAULT”);xSysLastValue::getLast(element);}
    public void run(){super();if(x)xctrl.text(x);// sxctrl is a string control on the form.}
    public container pack(){

    return [#CurrentVersion,#CurrentList];

    }

    public void close(){

    super();

    x= xctrl.text();

    xSysLastValue::saveLast(element);

    }

Standard