In some scenarios, we may need to allow users to select multiple values from a lookup within a grid on a form—for example, assigning multiple categories or tags to a line-level record. Out of the box, Dynamics 365 Finance and Operations does not support multi-select lookups directly on grid controls. However, we can achieve this behavior by extending the SysLookupMultiSelectGrid framework.
Step 1: Create a Custom Class Based on SysLookupMultiSelectGrid
To begin, we need to create a custom class that extends SysLookupMultiSelectGrid. This class will encapsulate the logic for initializing the lookup, storing selected values, and writing them back to the grid’s data source.
Here are the key methods you should implement:
init(): Register the lookup override and capture context such as the caller data source and field.
lookup(FormStringControl _callerControl): Open the lookup form and load existing values into the selection. After the user makes a selection, update the data source field.
getSelected(): Return the container of selected record IDs.
setSelected(): Persist the selected values into a specific field (usually a semicolon-delimited string field).
construct(…): A static method to initialize the custom multi-select lookup instance.
By implementing these methods, your custom control can support seamless multi-selection directly from the form grid.
///<summary> /// Willie Yao - 07/07/2025 /// getSelected ///</summary> ///<returns>container</returns> public container getSelected() { Array markedRecords; Common common; int i; int recordsMarked = 0;
Once the custom lookup class is ready, the next step is to integrate it into the form grid where multi-selection is required.
In the FormControl method override (usually on the lookup() method of the relevant control), you can instantiate your custom lookup using the construct() method.
MainGrid_OrderCategory is the name of the string control (usually bound to a field like OrderCategory) on the form grid.
query is a standard Query object used to define the records shown in the lookup.
con is a container specifying which field(s) to select and return from the lookup records.
This setup allows the form to display a multi-select lookup when users interact with the field in the grid, enabling them to choose multiple entries and store them in a semicolon-delimited format (or another structure as needed).