On Selection Change
- Last UpdatedAug 02, 2023
- 1 minute read
Use scripts for the onSelectionChange event of a Hierarchy Selector widget to perform a particular operation when transitioning from select to deselect state.
This event is triggered when a child node is selected or deselected. A child node is deselected when a parent or group node is selected, or a breadcrumb trail is selected. When the same child node is selected multiple times continuously or there is a constant deselect state, this event is triggered only once.
When a child node is selected or deselected, the value is fetched from the widget's Selected Object and Selected Value properties through scripting. A stringify null value is passed through the Selected Object (selectedObj) and Selected Value (selectedValue) properties on a deselect state.
Example
In the following example the selectedObj and selectedValue widget properties are used to passed the value of the selected reason object and the different properties within the reason object into the specified controls.
if(control.findByXmlNode("Widget1").widgetProperties.selectedObj != null && control.findByXmlNode("Widget1").widgetProperties.selectedObj != '')
{
var x = JSON.parse(control.findByXmlNode("Widget1").widgetProperties.selectedObj);
var y = JSON.parse(control.findByXmlNode("Widget1").widgetProperties.selectedValue);
var v = null;
if(x != null)
{
for(var prop in x)
{
if(x.hasOwnProperty(prop))
{
v = v+ prop + ": "+x[prop] + "\n";
}
}
control.findByXmlNode("ReasonAttribute1").value = x.reas_cd;
control.findByXmlNode("MESReasonselectedGroupID").value = x.reas_grp_id;
control.findByXmlNode("ReasonAttribute2").value = x.reas_desc;
control.findByXmlNode("ReasonAttribute3").value = x.color;
}
else
{
control.findByXmlNode("ReasonAttribute1").value = "";
control.findByXmlNode("MESReasonselectedGroupID").value = "";
control.findByXmlNode("ReasonAttribute2").value = "";
control.findByXmlNode("ReasonAttribute3").value = "";
}
var z = 'selected Value :'+y + "\n";
z += 'selected Obj :'+v;
control.findByXmlNode("selectedValueWidget2").value = '' + y;
control.findByXmlNode("ReturnwholeObjectvaluesWidget2").value = z;
}