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();
    }
}

2 yorum:

  1. Help me, my environment does not recognize the MultiSelectionHelper class.

    YanıtlaSil
    Yanıtlar
    1. Hi, are you sure if doesn't recognize? What error do you get? Which version of your AX?

      Sil