Dynamics 365 FO PU15: Create multiselect lookup control in out of box form

Recently came across the situation where we need to create the multi select lookup in the out of box form, As we knew in previous versions we have an option of over layering but from PU15 version they have completely restricted the over layering concept. Because of the same it was impossible for us to use the previous workaround for multi select lookup using SysLookupMultiSelectCtrl class as we have to declare the variable of it globally which is not possible in out of box form's extension in PU15 version of Dynamics 365 FO.

At the end of all and like always we found the solution for the multi select lookup within the Dynamics 365 FO only, There are out of box two classes used to build the multi select lookup, you can take below both class as a reference and create your solution,
  • ERDataAreaIdLookup
  • ERSysLookupMultiSelectGrid
I am giving the source code of above both class for your reference so you dont have to dig into AOT and check,

internal class ERDataAreaIdLookup
{
    internal static ERSysLookupMultiSelectGrid performMultiselectLookup(FormStringControl _callingCtrl, FormStringControl _recIdsControl, FormStringControl _strIdsControl, str _currentStrIds)
    {
        Query lookupQuery = new Query();

        var selectField = [tableNum(ERDataAreaView), fieldNum(ERDataAreaView, id)];

        QueryBuildDataSource dataAreaDS = lookupQuery.addDataSource(tableNum(ERDataAreaView));
        dataAreaDS.addSelectionField(fieldNum(ERDataAreaView, id));
        dataAreaDS.addSelectionField(fieldNum(ERDataAreaView, name));
        
        dataAreaDS.addSortField(fieldNum(ERDataAreaView, id));

        return ERSysLookupMultiSelectGrid::lookup(lookupQuery, selectField, _callingCtrl, _recIdsControl, _strIdsControl, _currentStrIds);
    }

}

internal class ERSysLookupMultiSelectGrid extends SysLookupMultiSelectGrid
{
    #SysOperation
    private const str CollectionValueSeparator = #CollectionValueSeparator;

    internal static ERSysLookupMultiSelectGrid lookup(Query _query, container _selectField, FormStringControl _callingCtrl, FormStringControl _recIdsControl, FormStringControl _strIdsControl, str _currentStrIds, queryRun _queryRun = null)
    {
        _strIdsControl.text(_currentStrIds);
        _recIdsControl.text('');

        var lookupMS = new ERSysLookupMultiSelectGrid();

        lookupMS.parmCallingControl(_callingCtrl);
        lookupMS.parmCallingControlId(_recIdsControl);
        lookupMS.parmCallingControlStr(_strIdsControl);
        lookupMS.parmQuery(_query);
        lookupMS.parmQueryRun(_queryRun);
        lookupMS.parmSelectField(_selectField);
        lookupMS.run();

        return lookupMS;
    }

    internal container getSelectedStrings()
    {
        return selectedStr;
    }

    internal SysLookupMultiSelectValues getSelectedStringsJoined()
    {
        return SysOperationHelper::convertMultiSelectedValueString(selectedStr);
    }

    internal static boolean stringListContainsItem(str _stringList, str _possibleItem)
    {
        container items = str2con(_stringList, CollectionValueSeparator);
        for (int i = 1 ; i <= conLen(items) ; i++)
        {
            str item = conPeek(items, i);
            if (item == _possibleItem)
            {
                return true;
            }
        }
        return false;
    }

}

If you still have any query please write me in the comment,

Cheers!!

Comments

Popular Posts