Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Get list of all printers and save selected choice

Sohaib Cheema Profile Picture Sohaib Cheema 46,614 User Group Leader

Past week found a task to work with an old version where it was required to get and set list of all printers attached to machine. This includes, AOS Printer, which are not connected to local client machine, as well as locally connected printers to that specific machine. Please allow me to share the x++ code that was tested and used in AX2009 version.

 

//<Variables Declaration>
PrintJobSettings printJobSettings; sysPrintOptions sysPrintOptions; map printerMap; mapIterator mapIterator; //<Variables Declaration>

printJobSettings = SysPrintOptions::newPrintJobSettingsOnServer(YourTableObjectName.FieldName);
sysPrintOptions = new sysPrintOptions();
sysPrintOptions.setPrintJobSettings(printJobSettings);
sysPrintOptions.buildPrinterMap();
printerMap = sysPrintOptions.getPrinterMap();
mapIterator = new mapIterator(printerMap);
mapIterator.begin();
while (mapIterator.more())
{
    mapIterator.next();
}
printJobSettings.printerSettings('SysPrintForm');
YourTableObjectName.FieldName = printJobSettings.packPrintJobSettings();
YourTableObjectName.update();

Basically we are getting list of all printers, saving those into a map and then finally saving the selected value of printer (by user) to a container. This is for required funcationality reasons. It’s almost same funcationality as you can select printers in print management.

For particular document/report they did not extended print management framework and instead followed shortcut of saving printer settings in a table. This could be used later at any point. E.g. you may want to print a report using batch job, on a particular printer (which is defined already in a table/setup form)

 




Comments

*This post is locked for comments