multiselect etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
multiselect etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

15 Kasım 2017 Çarşamba

AX 2012 - Multiselect Lookup

There is a class and a sample form (tutorial_LookupMultiSelectGrid) at AOT for generate multi select lookup:

public class FormRun extends ObjectRun
{
    SysLookupMultiSelectCtrl msCtrl;
}


public void init()
{
   ...  
    super();
    ...
    
    msCtrl = SysLookupMultiSelectCtrl::construct(element, InventLocationIdExc, queryStr(InventLocationSRS));
    msCtrl.set(this.InventLocationList());
    ...
}

We can get list like below and set like up in init.

container InventLocationList()
{
    Container           Ids,Names;
    InventLocation      location;
    int i;
    RecId               recId;

    for (i=1;i<=conLen(vInventLocationIdExc);i++)
    {
        recId = conPeek(vInventLocationIdExc,i);
        select firstOnly location
            where location.RecId == recId;
        Ids += location.RecId;
        Names += location.InventLocationId;
    }

    return [Ids,Names];
}

We can save like this at Pack method:

container pack()
{
    ...
    vInventLocationIdExc    = msCtrl.get();
    ...
}

While MsCtrl.get() gives us RecId values below gives us field values:

container               c = msCtrl.getSelectedFieldValues();

22 Ocak 2016 Cuma

Axapta - Why sometimes MultiSelectionHelper and why sometimes traditional read?

That's the  traditional way to read selected records from a grid:

 c = CustTable_DS.getFirst(true);
 while (c.RecId != 0)
 {
      info(c.Name);
      c = CustTable_DS.getNext();
 }


But there's a problem with this way. If user just wants to process records at line instead of select a couple of records unfortunately that record will be missed. That's the workaround for this symptom:


c = CustTable_DS.getFirst(true);
noSelected = true;
while (c.RecId != 0)
{
     noSelected = false;
     info(c.Name);
     c = CustTable_DS.getNext();

}
if  (noSelected)
    info(CustTable.Name);

MultiSelectionHelper solves this problem:

 MultiSelectionHelper helper = MultiSelectionHelper::construct();
CustTable c;
;

helper.parmDatasource(CustTable_ds);

c = helper.getFirst();
while (c.RecId != 0)
{
      info(c.Name);
      c = helper.getNext();

}


But there is a disadvantage for MultiSelectionHelper class too. If user wants to sort records at grid and wants to process with this sorted list we have to use traditional way again  because unfortunately MultiSelectionHelper doesn't care about users sort.

Using MultiselectionHelper from a class:

public static void main(Args _args)
{
    SMAServiceOrderTable    serviceOrder;
    MultiSelectionHelper    helper;
    FormRun                 caller = _args.caller();
    FormDataSource          SMAServiceOrderTable_DS;
  
    SMAServiceOrderTable_DS = caller.dataSource();
    helper = MultiSelectionHelper::createFromCaller(caller);
    helper.createQueryRanges(SMAServiceOrderTable_DS.queryBuildDataSource(),fieldStr(SMAServiceOrderTable,RecId));
    
    serviceOrder = helper.getFirst();
    
    while(serviceOrder)
    {
        info(strFmt("%1",serviceOrder.RecId));
        serviceOrder = helper.getNext();
    }
}