Create multi select company lookup in report dialogue using X++


Create multi select company lookup in dialogue using X++


Let’s say we have a requirement to show multi select lookup on report dialogue box.

Steps:

1) Create CONTRACT class with a company parameter in it.
2) Create UI BUILDER Class to make multi select company lookup
3) Get selected companies in Report DP class

Let’s put some lights on the above steps. Assuming that we know the basic concepts of SysOperationFramework.

Create CONTRACT class with a company parameter in it.


Adding SysOperationContractProcessingAttribute in contract class will use controls modified in UI Builder class.
Use LIST as a data type as we can have multiple selected companies.

Code:


[
DataContractAttribute,   SysOperationContractProcessingAttribute(classStr(TestReportUIBuilder))
]
class TestReporContract
{
    List    legalEntity;
}

Now add new method for company parameter mentioned below.


Code:


[
    DataMemberAttribute('LegalEntity'),
    AifCollectionTypeAttribute('Entity', Types::String)
]
public List parmLegalEntity(List _value = legalEntity)
{
    if(legalEntity == null)
    {
        legalEntity = new List(Types::String);
    }

    if(_value != null)
    {
        legalEntity = new List(Types::String);
        legalEntity.appendList(_value);
    }

    return legalEntity;
}


Create UI BUILDER class to make multi select company lookup


Declare variables to use it in company lookup.
Extend class with SysOperationAutomaticUIBuilder to use its method for modifying controls.

Code:


class TestReportUIBuilder extends SysOperationAutomaticUIBuilder
{
    DialogField dfEntities;

    SysLookupMultiSelectCtrl    msCtrl;

    TestReportContract contract;
}



public void build()
{
    super();
}


public void postRun()
{
    contract     = this.dataContractObject();
    dfEntities   = this.bindInfo().getDialogField(contract,
                   methodStr(TestReportContract, parmLegalEntity));

    if(dfEntities)
    {
        this.createEntityLookup(dfEntities.control());
    }
}


private void createEntityLookup(FormStringControl  _control)
{
    container   compCon = [tableNum(CompanyInfo),
                           fieldNum(CompanyInfo,DataArea)];
    Query       query = new Query();
    QueryBuildDataSource qbds;

    qbds = query.addDataSource(tableNum(CompanyInfo));
    qbds.addSelectionField(fieldNum(CompanyInfo, DataArea));
    qbds.addSelectionField(fieldNum(CompanyInfo, Name));
    qbds.addOrderByField(fieldNum(CompanyInfo, DataArea));

    msCtrl SysLookupMultiSelectCtrl::constructWithQuery
            (this.dialog().formRun(),_control, 
             query, true, compCon);
}


Parameters of SysLookupMultiSelectCtrl::constructWithQuery()

1  FormRun
2  FormStringControl
3  Query
4  IsMandatory
5  Container


Get selected companies in Report DP class.


Now we have to get the selected companies in DP class in order to process data on multiple companies.
Create new class: TestReportDP and extend it with SrsReportDataProviderBase to override its method in the DP class.

Code:


[
    SRSReportQueryAttribute(queryStr(query)),
    SRSReportParameterAttribute(classStr(TestReportContract))
]
class TestReportDP extends SrsReportDataProviderBase  
{
   
}


Add ProcessReport() method.
Use below code to iterate through selected companies.

Code:


[SysEntryPointAttribute(false)]
public void processReport()
{
    TestReportContract dataContract = this.parmDataContract() as
                                      TestReportContract;
    ListEnumerator  lenum;

    CompanyId       company;

    lenum = dataContract.parmLegalEntity().getEnumerator();

    while(lenum.moveNext())
    {
        company = lenum.current();
        this.processCompany(company);
    }  
}

We can now use selected companies according to our need in fetching report data.

Comments

Popular posts from this blog

Cross Company queries - X++

Positive pay file in D365