Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 64797

How to add Printer lookup in AX 2012

$
0
0
1. Create a class or add below method to use it globally:

Class printers
{

}

//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 = newMicrosoft.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;
}

2. Build lookup Method

public staticvoidprinterLookup(FormControl _formControl)
{
    SysTableLookup                  sysTableLookup;
    TmpTableFieldLookup             tmpTableFieldLookup;
    Enumerator                      en;
    List                            entitylist      = newlist(types::String);
    Map                             printerMap;
    MapEnumerator                   enumerator;
    PrinterName                     printerName;

    printerMap          = printerMap();//If above method was created in Global class else call specificclass 
    enumerator          = printerMap.getEnumerator();
    while (enumerator.moveNext())
    {
        printerName = enumerator.currentValue();
        entitylist.addend(printerName);
    }

    en = entityList.getEnumerator();

    while (en.moveNext())
    {
        tmpTableFieldLookup.TableName = en.current();
        tmpTableFieldLookup.insert();
    }

    sysTableLookup = SysTableLookup::newParameters(tableNum(tmpTableFieldLookup), _formControl);
    sysTableLookup.addLookupfield(fieldNum(TmpTableFieldLookup, TableName));
    sysTableLookup.setLabel("@SYS62708");

    //BP Deviation documented
    sysTableLookup.parmTmpBuffer(tmpTableFieldLookup);
    sysTableLookup.performFormLookup();
}



Viewing all articles
Browse latest Browse all 64797

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>