Search This Blog

Thursday, June 25, 2015

Editable Multi select lookup in Grid field AX2012

Scneario: Multiple select Editable lookup  in grid

I created an extension of class from SysLookupMultiselectGrid

class KrisSysLookupMultiSelectGrid extends SysLookupMultiSelectGrid
{
#Characters
}

public void setSelected()
{
 dictfield dictField;
 Common currentDSRecord;
 FormDataSource formdatasource;
 callingControlId.text(SysOperationHelper::convertMultiSelectedValueString       (selectedId));
 formdatasource = callingControlId.dataSourceObject();
 if(formdatasource && callingControlStr.dataField())
 {
  dictfield = new dictfield(formdatasource.table(),callingControlStr.dataField());
   currentDSRecord = formdatasource.cursor();
   currentDSRecord.(dictfield.id()) = currentDSRecord.(dictfield.id()) +     SysOperationHelper::convertMultiSelectedValueString(selectedStr);
  callingControlStr.update();
 }
 else
 {
 callingControlStr.text(SysOperationHelper::convertMultiSelectedValueString(selectedStr));
 }
}

public static KrisSysLookupMultiSelectGrid construct(FormControl _ctrlId,
FormControl _ctrlStr)
{
KrisSysLookupMultiSelectGrid lookupMS;
lookupMS = new KrisSysLookupMultiSelectGrid ();
lookupMS.parmCallingControlId(_ctrlId);
lookupMS.parmCallingControlStr(_ctrlStr);
return lookupMS;

}


On form declare this class on the form level as below

KrisSysLookupMultiSelectGrid multiSelectGrid;

On form Init method initiliaze this object as below
multiSelectGrid = KrisSysLookupMultiSelectGrid ::construct(GridResults_Value,GridResults_Value);

On grid string edit field lookup method you can use this object as below

Query query = new Query();

QueryBuildDataSource queryBuildDataSource;

queryBuildDataSource = query.addDataSource(tableNum(DimensionAttribute));
queryBuildDataSource.addRange(fieldNum(DimensionAttribute,Type)).value(queryValue(DimensionAttributeType::CustomList));
queryBuildDataSource.addRange(fieldNum(DimensionAttribute,Type)).value(queryValue(DimensionAttributeType::MainAccount));
queryBuildDataSource.addRange(fieldNum(DimensionAttribute,Type)).value(queryValue(DimensionAttributeType::ExistingList));
queryBuildDataSource.addSelectionField(fieldNum(DimensionAttribute,Name));
multiSelectGrid.parmQuery(query);

multiSelectGrid.run();

you can see in form as below screenshot


Its editable and multi select lookup.



1 comment:

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.