Multi select in x++ - Song Nghia - Technical Consultant

Dynamic 365 FO Dynamic 365 Retail

Thứ Ba, 11 tháng 1, 2022

Multi select in x++

 Multi select in x++

Nghia Song  - Technical Consultant


public class AmicisAdaptAllRegionProductRestrictionEventHandler
{
    [FormControlEventHandler(formControlStr(AmicisRegionProductRestriction, AmicisRegionProductRestriction_PaymentRestriction), FormControlEventType::Lookup)]
    public static void AmicisRegionProductRestriction_PaymentRestriction_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        Query                   query = new Query();
        QueryBuildDataSource    queryBuildDataSource;
        SysTableLookup          sysTableLookup;
        
        sysTableLookup = SysTableLookup::newParameters(tableNum(AmicisRegionProductRestriction), sender);
        queryBuildDataSource = query.addDataSource(tableNum(AmicisAdaptAllTagRestrictionConfiguration));
        queryBuildDataSource.addSelectionField(fieldNum(AmicisAdaptAllTagRestrictionConfiguration, RetailTenderTypeId));
        queryBuildDataSource.addRange(fieldNum(AmicisAdaptAllTagRestrictionConfiguration, RetailTenderTypeId)).value(SysQuery::valueNot(""));
        queryBuildDataSource.addSelectionField(fieldNum(AmicisAdaptAllTagRestrictionConfiguration, RetailTenderTypeName));
        
        container selectFields = [tableNum(AmicisAdaptAllTagRestrictionConfiguration),fieldNum(AmicisAdaptAllTagRestrictionConfiguration,RetailTenderTypeId)];

        AmicisAdaptAllSysLookupMultiSelectGrid multiSelectGrid = AmicisAdaptAllSysLookupMultiSelectGrid ::construct(sender ,sender);
        multiSelectGrid.parmQuery(query);
        multiSelectGrid.parmCallingControl(sender);
        multiSelectGrid.parmSelectField(selectFields);
        multiSelectGrid.pclParmSelectId(conNull());

        multiSelectGrid.run();
        multiSelectGrid.getSelected();
    }

}


class AmicisAdaptAllSysLookupMultiSelectGrid extends SysLookupMultiSelectGrid
{
    #Characters
    public void setSelected()
    {
        dictfield dictField;
        Common currentDSRecord;
        FormDataSource formdatasource;
        callingControlId.text(SysOperationHelper::convertMultiSelectedValueString(selectedId));
        formdatasource = callingControlId.dataSourceObject();
        if(formdatasource && callingControlStr.dataField())
        {
            dictfield = new dictfield(formdatasource.table(),callingControlStr.dataField());
            currentDSRecord = formdatasource.cursor();
            currentDSRecord.(dictfield.id()) = SysOperationHelper::convertMultiSelectedValueString(selectedStr);
            callingControlStr.update();
        }
        else
        {
            callingControlStr.text(SysOperationHelper::convertMultiSelectedValueString(selectedStr));
        }
    }

    public static AmicisAdaptAllSysLookupMultiSelectGrid construct(FormControl _ctrlId, FormControl _ctrlStr)
    {
        AmicisAdaptAllSysLookupMultiSelectGrid lookupMS;
        lookupMS = new AmicisAdaptAllSysLookupMultiSelectGrid ();
        lookupMS.parmCallingControlId(_ctrlId);
        lookupMS.parmCallingControlStr(_ctrlStr);
        return lookupMS;
    }

    public container pclParmSelectId(container _selectedId = selectedId)
    {
        selectedId = _selectedId;
        return selectedId;
    }

}