To get the printer names lookup in ax and dialog override method and last dialog values store next time dialog opens:
/// <summary>
/// to show the printer name lookup
/// </summary>
class MSSpindleLabelLookup extends RunBase
{
dialog dialog;
dialogGroup dialogGroup;
dialogField dialogField;
PrinterName getPrinterName;
container _dialogValues;
}
/// <summary>
/// to get the dialog
/// </summary>
/// <returns>
/// returns printer name what you selected
/// </returns>
/// <remarks>
/// to get the dialog
/// </remarks>
/// <exception cref="Exception::Error">
/// if user cancel the printing
/// </exception>
protected Object dialog()
{
FormStringControl systemprinterNames;
;
dialog = new Dialog("@MPR5759");
dialogGroup = dialog.addGroup("@SYS62708");
dialogField = dialog.addField(extendedTypeStr(PrinterName));
systemprinterNames = dialogField.fieldControl();
systemprinterNames.registerOverrideMethod(methodStr(FormStringControl, lookup), MethodStr(MSSpindleLabelLookup, msprinterLookup), this);
systemprinterNames.mandatory(true);
//Get the previouse values
_dialogValues = xSysLastValue::getValue(curExt(), curUserId(), UtilElementType::Job, "@SYS62708");
//Check if we have previouse values
if(_dialogValues != conNull())
{
dialogField.value(conPeek(_dialogValues, 1));
}
if (dialog.run())
{
//Save the user choices
_dialogValues = conNull();
_dialogValues += dialogField.value();
xSysLastValue::putValue(_dialogValues, curExt(), curUserId(), UtilElementType::Job, "@SYS62708");
}
if(dialog.closedOk() == false)
throw error("@MPR5760");
return Dialog;
}
/// <summary>
/// get the lookup
/// </summary>
/// <param name="_formControl">
/// passing string control
/// </param>
public void msprinterLookup(FormStringControl _formControl )
{
SysTableLookup sysTableLookup;
TmpTableFieldLookup tmpTableFieldLookup;
Enumerator en;
List entitylist = new list(types::String);
Map printerMap;
MapEnumerator enumerator;
PrinterName printerName;
printerMap = MSSpindleLabelLookup::printerMap();//If above method was created in Global class else call specific class
enumerator = printerMap.getEnumerator();
while (enumerator.moveNext())
{
printerName = enumerator.currentValue();
entitylist.addend(printerName);
}
en = entityList.getEnumerator();
while (en.moveNext())
{
tmpTableFieldLookup.MSprinterName = en.current();
tmpTableFieldLookup.insert();
}
sysTableLookup = SysTableLookup::newParameters(tableNum(tmpTableFieldLookup), _formControl);
sysTableLookup.addLookupfield(fieldNum(TmpTableFieldLookup, MSprinterName));
sysTableLookup.setLabel("@SYS62708");
//BP Deviation documented
sysTableLookup.parmTmpBuffer(tmpTableFieldLookup);
sysTableLookup.performFormLookup();
}
/// <summary>
/// run the dialog
/// </summary>
/// <returns>
/// get the printer name
/// </returns>
public PrinterName runPrinterLookup()
{
this.dialog();
getPrinterName = dialogField.value();
return getPrinterName;
}
public static MSSpindleLabelLookup construct()
{
return new MSSpindleLabelLookup();
}
public static void main(Args args)
{
MSSpindleLabelLookup MSSpindleLabelLookup = MSSpindleLabelLookup::construct();
MSSpindleLabelLookup.runPrinterLookup();
}
//This method loads all available printers to a Map object
static Map printerMap()
{
Microsoft.Dynamics.AX.Framework.Reporting.Shared.PrinterHelper printerHelper;
Microsoft.Dynamics.AX.Framework.Reporting.Shared.PrinterInfo printerInfo;
System.Collections.ArrayList names;
System.Collections.IEnumerator enumerator;
Map printerMap;
str name;
int printerStatus;
str driverName;
str portName;
str comments;
int jobCountSinceLastReset;
if(!printerMap)
{
printerMap = new Map(Types::String, Types::Container);
// BP Deviation documented
printerHelper = new Microsoft.Dynamics.AX.Framework.Reporting.Shared.PrinterHelper();
names = printerHelper.get_PrinterNames();
if (names != null)
{
enumerator = names.GetEnumerator();
while (enumerator.MoveNext())
{
name = enumerator.get_Current();
printerInfo = printerHelper.GetPrinterInfo(name);
// BP Deviation documented
printerStatus = CLRInterop::getAnyTypeForObject(printerInfo.get_PrinterStatus());
// BP Deviation documented
driverName = CLRInterop::getAnyTypeForObject(printerInfo.get_DriverName());
// BP Deviation documented
portName = CLRInterop::getAnyTypeForObject(printerInfo.get_PortName());
// BP Deviation documented
comments = CLRInterop::getAnyTypeForObject(printerInfo.get_Comment());
// BP Deviation documented
jobCountSinceLastReset = CLRInterop::getAnyTypeForObject(printerInfo.get_JobCountSinceLastReset());
printerMap.insert(name, [name, printerStatus, driverName, portName, comments, jobCountSinceLastReset]);
}
}
}
return printerMap;
}