Wednesday, January 20, 2021

SSRS Make Enum Multi Select AX 2012

In this tutorial we see how to make Enum Multi Select in ax 2012 and filter values in another lookup based on Enum values. 

Make new table and add fields in it  EnumId and EnumLabel. write the method in the UI builder class you can see the method below.

public void ContactStatusLookup(FormStringControl _control)

{

    Query                       query = new query();

    QueryBuildDataSource        qbds;

    BEContractStatusEnum        enumTmp; //Table name

    SysDictEnum                 dictEnum = new SysDictEnum(enumNum(BEContractStatus));

    int                         idx;


    delete_from enumTmp;


    for (idx = 0;idx < dictEnum.values();idx++)

    {

       enumTmp.clear();

       enumTmp.initValue();

       enumTmp.EnumId       = dictEnum.index2Value(idx);

       enumTmp.EnumLabel    = dictEnum.index2Label(idx);

       enumTmp.insert();

    }



    qbds = query.addDataSource(tableNum(BEContractStatusEnum));


    qbds.fields().dynamic(false);

    qbds.fields().clearFieldList();


    qbds.fields().addField(fieldNum(BEContractStatusEnum, EnumLabel));

    //SysLookupMultiSelectGrid::lookup(query,_control,_control,conNull());

    multiContractStatus = SysLookupMultiSelectGrid::construct(_control, _control);

    multiContractStatus.parmQuery(query);

    multiContractStatus.run();


}

Register this method in post build.

Now we filter values in another lookup see the below code how we filter values based on selected values in enum lookup.

public void ContactIDLookup(FormStringControl _control)

{

    str                             controlValue;

    Query                           query = new query();

    QueryBuildDataSource            qbds;

    List                            strlist=new List(Types::String);

    ListIterator                    iterator;

    SysDictEnum                     dictEnum = new SysDictEnum( enumnum(BEContractStatus) );


    qbds = query.addDataSource(tableNum(BEContractDetails));

    controlValue = contractStatus.value();

    qbds.fields().dynamic(false);

    qbds.fields().clearFieldList();

    if(dictEnum.name2Value(contractStatus.value()) !=0 && controlValue!="")

    {

        strlist     =   strSplit(controlValue,";");

        iterator    = new ListIterator(strlist);


        while(iterator.more())

        {

            //info(strFmt("%1 - %2 - %3",iterator.value(), , dictEnum.index2Symbol(dictEnum.name2Value(contractStatus.value()))));

            qbds.addRange(fieldNum(BEContractDetails, EndUseragreementStatus)).value(SysQuery::value(dictEnum.index2Symbol(dictEnum.name2Value(iterator.value()))));

            qbds.fields().addField(fieldNum(BEContractDetails, ContractId ));

            qbds.fields().addField(fieldNum(BEContractDetails, ClientName ));

            qbds.fields().addField(fieldNum(BEContractDetails, PropertyId ));

            iterator.next();

        }

    }

    else

    {

        qbds.fields().addField(fieldNum(BEContractDetails, ContractId ));

        qbds.fields().addField(fieldNum(BEContractDetails, ClientName ));

        qbds.fields().addField(fieldNum(BEContractDetails, PropertyId ));

    }

    //SysLookupMultiSelectGrid::lookup(query,_control,_control,conNull());

    multiContractId = SysLookupMultiSelectGrid::construct(_control, _control);

    multiContractId.parmQuery(query);

    multiContractId.run();

}

No comments:

Post a Comment

Please do not add any spam link in the comment box.