Multi-select parameters in dialogs

Example of RunBaseBatch based job with multi-select parameter (wharehouses)
class MultiSelectRunBaseBatch extends RunBaseBatch
{
    container                   warehouses;
    SysLookupMultiSelectCtrl    warehouseMultiSelect;
    FormBuildStringControl      warehouseCtrl;
    DialogField                 warehousesField;

    #define.CurrentVersion(1)
    #localMacro.CurrentList
        warehouses
    #endmacro
}

protected Object dialog()
{
    DialogRunbase       dialog;
    DialogGroup         dialogGroup;
    FormBuildControl    formBuildControl;

    dialog = super();

    dialog.allowUpdateOnSelectCtrl(true);

    dialogGroup         = dialog.addGroup();
    formBuildControl    = dialog.formBuildDesign().control(dialogGroup.formBuildGroup().id());
    warehouseCtrl       = formBuildControl.addControl(FormControlType::String, identifierstr(InventLocationId));
    warehouseCtrl.label("@SYS6437");

    return dialog;
}

public void dialogPostRun(DialogRunbase dialog)
{
    FormRun                 formRun;
    FormStringControl       fsCtrlWarehouse;
    Query                   q;
    QueryBuildDataSource    qbds;

    q       = new Query();
    qbds    = q.addDataSource(tablenum(InventLocation));

    qbds.addSelectionField(fieldNum(InventLocation, InventLocationId));
    qbds.addSelectionField(fieldNum(InventLocation, Name));

    super(dialog);

    formRun = dialog.dialogForm().formRun();

    if (formRun)
    {
        fsCtrlWarehouse = formRun.design().control(warehouseCtrl.id());
        warehouseMultiSelect = SysLookupMultiSelectCtrl::constructWithQuery(formRun, fsCtrlWarehouse, q);
        warehouseMultiSelect.set([this.warehouseIdsToRecIds(warehouses), warehouses]);
    }
}

public boolean getFromDialog()
{

    boolean ret;

    ret             = super();
    warehouses      = this.warehouseRecIdsToIDs(warehouseMultiSelect.get());

    return ret;
}

public container pack()
{
    return [#CurrentVersion, #CurrentList];
}

public void run()
{
}

public boolean unpack(container packedClass)
{
    Version version = RunBase::getVersion(packedClass);

    switch (version)
    {
        case #CurrentVersion:
            [version, #CurrentList] =  packedClass;
            break;

        default:
            return false;
    }

    return true;
}

public static MultiSelectRunBaseBatch construct()
{
    return new MultiSelectRunBaseBatch();
}

client server static ClassDescription description()
{
    return "Multi-select run base batch";
}

public static void main(Args _args)
{
    MultiSelectRunBaseBatch batch = MultiSelectRunBaseBatch::construct();

    if (batch.prompt())
    {
        batch.run();
    }
}

public container warehouseIdsToRecIds(container _warehouseIds)
{
    InventLocation      inventLocation;
    InventLocationId    inventLocationId;
    container           warehouseRecIds;
    int                 i;

    warehouseRecIds = conNull();

    for (i = 1; i <= conLen(_warehouseIds); i++)
    {
        inventLocationId = conPeek(_warehouseIds, i);

        select firstOnly RecId from inventLocation
        where inventLocation.InventLocationId == inventLocationId;

        warehouseRecIds += [inventLocation.RecId];
    }

    return warehouseRecIds;
}

public container warehouseRecIdsToIDs(container _warehouseRecIds)
{
    InventLocation  inventLocation;
    RecId           inventLocationRecId;
    container       warehouseIds;
    int             i;

    warehouseIds = conNull();

    for (i = 1; i <= conLen(_warehouseRecIds); i++)
    {
        inventLocationRecId = conPeek(_warehouseRecIds, i);
        select firstOnly InventLocationId from inventLocation
        where inventLocation.RecId == inventLocationRecId;

        warehouseIds += [inventLocation.InventLocationId];
    }

    return warehouseIds;
}



 

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags