Показать сообщение отдельно
Старый 19.06.2018, 11:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
sunilrakesh: Treeview lookup in D365FO
Источник: https://community.dynamics.com/membe...d-4e6c628498d3
==============

Tree view lookups are not new but out of the box it made with EDT relations in earlier versions, but in D365FO EDT relations are deprecated, instead we can achieve through table references, here is a small example with steps. My requirement is like getting tree as an lookup in a ParentId field.

1. Create a table with relation as shown:
OperatingareaId field is my tree node trying to get lookup in ParentID field.



2. Create EDT for OperatingAreaId and give table reference of your table as show:
and give OperatingAreaId as reference & Formhelp with lookup form which we created down.



3. For ParentId field extend the EDT of OperatingAreaId and put table reference eith table name and give OperatingareaId as table reference.













1. Create a form lookup as shown above with datasource and with form tree control.
2. In run() method use your tree view class.
In this form we use tree class.(find existing class and build your own logic eg. Class smmSalesUnitTree)
sample code of form methods:[Form]

public class SupOperatingAreaLookup extends FormRun

{
SupplierOperatingAreaTree operatingAreaTree;

void exit()
{
int selection;
FormTreeItem formTreeItem;


selection = OperatingAreaTreeCtl.getSelection();
formTreeItem = OperatingAreaTreeCtl.getItem(selection);


if (formTreeItem && selection != OperatingAreaTreeCtl.getRoot())
{
element.closeSelect(formTreeItem.data());
}
}
public void run()

{
str selectedValue = "";


operatingAreaTree = new SupplierOperatingAreaTree(SupplierOperatingArea_ds, OperatingAreaTreeCtl,

fieldNum(SupplierOperatingArea, OperatingAreaId),

fieldNum(SupplierOperatingArea, ParentId),

fieldNum(SupplierOperatingArea, Description),

false);


if (element.args() && element.args().dataset())
{
FormStringControl callerControl = SysTableLookup::getCallerStringControl(element.args());
selectedValue = callerControl.text();
}


if (selectedValue)
{
SupplierOperatingArea supOpeArea = SupplierOperatingArea::find(selectedValue);

operatingAreaTree.initRoot("Operating area", supOpeArea.RecId);
operatingAreaTree.expandAndSelect(supOpeArea);
}
else
{
operatingAreaTree.initRoot("Operating area", '');
}


super();
}
int task(int p1)
{
#Task


int ret;


ret = super(p1);


if (p1 == #taskEnter)
{
element.exit();
}


return ret;
}
[DataSource]
class SupplierOperatingArea
{
public void init()
{
super();
this.addFieldToSelectionList(fieldNum(SupplierOperatingArea,OperatingAreaId));

this.addFieldToSelectionList(fieldNum(SupplierOperatingArea, ParentId));

this.addFieldToSelectionList(fieldNum(SupplierOperatingArea, Description));

}
public void executeQuery()
{
super();
operatingAreaTree.selectDatasource();

}
}
[Control("Tree")]
class OperatingAreaTreeCtl
{
public boolean expanding(int _idx, FormTreeExpand _action, anytype _data)
{
boolean ret;
ret = super(_idx, _action, _data);
operatingAreaTree.expanding(_idx, _action, _data);

return ret;
}
public void selectionChanged(FormTreeItem _oldItem, FormTreeItem _newItem, FormTreeSelect _how)
{
super(_oldItem, _newItem, _how);
operatingAreaTree.selectionChanged(_oldItem, _newItem);
if (_how == FormTreeSelect::ByMouse)
{
element.exit();
}

}
}
}









Источник: https://community.dynamics.com/membe...d-4e6c628498d3
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.