The trick is to create a new JSON object with the structure value in it and set it to the end of the list.
The other problem you're having is that your structure is read-only so it cannot be added to. You need to add access="1" to your definition.
var structCount = params.getElementCount('raceList');
if (structCount == 1 && params.getValue('raceList.0.identifier', 0) == "") // If this is the first element and it has not been set yet
{
structCount = 0;
}
var newValue = {
"name": "Name " + structCount,
"identifier": "ID " + structCount
};
params.setValue('raceList', structCount, newValue);
Here is a more complete custom panel example that shows adding elements to a structure and then using setAllValues to reset it:
<abs contexttype="opengear" style="">
<meta>
<params>
<param access="1" constrainttype="STRUCT" name="Race Definition" oid="raceDefinition" structtype="raceInfo" type="STRUCT" widget="36">
<value>
<subparam access="1" name="Race Name" suboid="name" type="STRING" value="Test"/>
<subparam access="1" name="Id" suboid="identifier" type="STRING" value="Test"/>
</value>
</param>
<param access="1" constrainttype="STRUCT" name="Race Definition" oid="raceList" structtype="raceInfo" templateoid="raceDefinition" type="STRUCT_ARRAY" widget="table">
<value>
<subparam suboid="name" value=""/>
<subparam suboid="identifier" value=""/>
</value>
</param>
</params>
</meta>
<param element="0" expand="true" height="308" left="17" oid="raceList" showlabel="false" top="17" width="448"/>
<button buttontype="push" height="53" left="18" name="Add" top="337" width="297">
<task tasktype="ogscript">var structCount = params.getElementCount('raceList');
if (structCount == 1 && params.getValue('raceList.0.identifier', 0) == "") // If this is the first element and it has not been set yet
{
structCount = 0;
}
var newValue = {
"name": "Name " + structCount,
"identifier": "ID " + structCount
};
params.setValue('raceList', structCount, newValue);</task>
</button>
<button buttontype="push" height="54" left="318" name="Clear" top="337" width="140">
<task tasktype="ogscript">var empty = [{"name":"", "identifier":""}];
params.setAllValues('raceList', empty);</task>
</button>
</abs>#DashBoard