Hi Dennis.
Here is an example of how to load this kind of data:
<abs contexttype="opengear" style="">
<meta>
<params>
<param access="1" constrainttype="INT_CHOICE" name="Constraint From XML" oid="Constraint_From_XML" precision="0" type="INT32" value="0" widget="combo">
<constraint key="0">Nothing</constraint>
</param>
</params>
<ogscript handles="onload">var newConstraint = params.createIntChoiceConstraint(["Nothing"]);
params.replaceConstraint('Constraint_From_XML', newConstraint);</ogscript>
</meta>
<param expand="true" height="90" left="32" oid="Constraint_From_XML" top="48" width="626"/>
<button buttontype="push" height="95" left="673" name="Load" top="47" width="183">
<task tasktype="ogscript">var xmlDocument = ogscript.parseXML('data.xml'); //Parse the XML
var nodeList = xmlDocument.getElementsByTagName("team"); //Get the tags we want to include in the constraint
var constraintData = []; //Placeholder for the new constraint data
if (constraintData.length == 0) //Placeholder if we don't have anything (OPTIONAL)
{
constraintData.push({"key": 0, "value": "Nothing"});
}
for (var i = 0; i < nodeList.getLength(); i++) //Loop through each tag we found
{
var node = nodeList.item(i); //Get the node
constraintData.push({"key": parseInt(node.getAttribute("ID")), "value": node.getAttribute("name")}); //Push the key/value pair
}
var constraint = params.createIntChoiceConstraint(constraintData); //Create the constraint
params.replaceConstraint("Constraint_From_XML", constraint); //Replace the constraint</task>
</button>
</abs>
The relevant bit is attached to the button:
var xmlDocument = ogscript.parseXML('data.xml'); //Parse the XML
var nodeList = xmlDocument.getElementsByTagName("team"); //Get the tags we want to include in the constraint
var constraintData = []; //Placeholder for the new constraint data
if (constraintData.length == 0) //Placeholder if we don't have anything (OPTIONAL)
{
constraintData.push({"key": 0, "value": "Nothing"});
}
for (var i = 0; i < nodeList.getLength(); i++) //Loop through each tag we found
{
var node = nodeList.item(i); //Get the node
constraintData.push({"key": parseInt(node.getAttribute("ID")), "value": node.getAttribute("name")}); //Push the key/value pair
}
var constraint = params.createIntChoiceConstraint(constraintData); //Create the constraint
params.replaceConstraint("Constraint_From_XML", constraint); //Replace the constraint
Here is the example XML data I was working with (I had it saved in a file called data.xml)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<teams>
<team ID="1" name="Red Team"/>
<team ID="2" name="Blue Team"/>
<team ID="3" name="Green Team"/>
</teams>
#DashBoard