Источник:
http://alexvoy.blogspot.com/2019/01/...rid-class.html
==============
<div dir="ltr" style="text-align: left;" trbidi="on">You can find a lot of example about how to support multiple selection lookups. AX 2012/D365 provide us with
SysLookupMultiSelectGrid class and form to implement such scenarios.
There are two bugs however still existing in the standard code.
SysLookupMultiSelectGrid class, method
lookup() must be as follows in order to refresh Query in case QueryRun is given.
// the standard method does
not update the query
in case
if queryrun
is given
public static void wblLookup(Query _query, FormStringControl _ctrlIds, FormStringControl _ctrlStrs, container _selectField, queryRun _queryRun
= null)
{
SysLookupMultiSelectGrid lookupMS
= new SysLookupMultiSelectGrid();
lookupMS
.parmCallingControlId(_ctrlIds);
lookupMS
.parmCallingControlStr(_ctrlStrs);
lookupMS
.parmQuery(_query);
lookupMS
.parmQueryRun(_queryRun);
// Begin: Alexey Voytsekhovskiy
{
lookupMS
.parmQuery(_queryRun
.query());
}
// End: Alexey Voytsekhovskiy
lookupMS
.parmSelectField(_selectField);
lookupMS
.run();
}
SysLookupMultiSelectGrid form, method
executeQuery() on common data source must be as follows in order not to consider referenced data sources, which may come with a given query.
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">public void executeQuery()
{
QueryRun qr;
Query lookupMultiSelectQueryCopy
= new Query(lookupMS
.parmQuery());
FormRun formRun;
FormDataSource formDataSource;
int dsCount, i
= 1;
Common formDataSourceCursor, queryRunCursor;
// Always use the query defined on the SysLookupMultiSelectGrid class
. Note that a copy
is used
// so that
any modifications made to the Query by the Form at runtime aren't fed back through
// the
next time the lookup
is presented to the user
. (The Query
is used to define which fields
// are present on the Form during lookup construction
. Therefore,
if any fields are added at runtime
// by the Forms engine, duplicated
or non
-original
-Query defined fields may be presented on the
// 2nd
or later presentations of the lookup
if a copy isn't used.)
this
.query(lookupMultiSelectQueryCopy);
// check
if user has
set any queryrun
. If yes, that means the cursors are
set by user explicitly,
// usually the case where query contains tmp tables
and needs to be populated
.
qr
= lookupMS
.parmQueryRun();
if(qr)
{
formRun
= this
.formRun();
dsCount
= formRun
.dataSourceCount();
// get data source
from query run, get the cursor
and set it on the form data source cursor
.
for(i
= 1; i<span style="color: #333333;">