getValueAsString will typically attempt to provide you the user-facing visible String which, in your case, will be different from the parameter's actual value. getValueString was used in this case as the same data structure is used for integer-based choice entries as it is for string-based choice entries so we needed a different getter to expose the String value as opposed to the Integer value.
Copying constraint internals from one instance to another is not a common task and appears to be a gap in the documentation. I will flag it to our technical writing staff so it can be addressed in the future. Until then, asking in the forum is definitely the fastest way to get moving again.
Original Message:
Sent: 02-15-2024 17:34
From: Evan Aaron
Subject: Add Key/Value Constraint to Param
Aha! That worked! Thanks James
Out of curiosity-- What is the difference between .getValueString and .getValueAsString from params object (which I did try and it didnt work)?
Where could I have found that .getValue method (besides asking you guys here :))
------------------------------
Evan Aaron
Engineer
Game Creek Video
Original Message:
Sent: 02-15-2024 16:59
From: James Peltzer
Subject: Add Key/Value Constraint to Param
Hi Evan
Great job adapting an existing example. You are VERY close on this one. The only change you need to make is to use getValueString() instead of getValue() when copying your existing choices to your new constraint.
var existValues = params.getConstraint('Sheet_ID').getChoices();var newName = params.getValue('new_Name', 0);var newID = params.getValue('new_ID',0);var newValues = []var numList = params.getConstraint("Sheet_ID");var choices = numList.getChoices();for (var i = 0; i < choices.length; i++) { newValues.push({"key": choices[i].getValueString(), "value": choices[i].getName()});}newValues.push({"key": newID, "value": newName}); var newCon = params.createStringStringChoiceConstraint(newValues);params.replaceConstraint('Sheet_ID', newCon);
------------------------------
James Peltzer
Ross Video
Original Message:
Sent: 02-13-2024 14:00
From: Evan Aaron
Subject: Add Key/Value Constraint to Param
Hi!
I am working on a panel where I am storing a Value as a Key Value Constraint in a param, so a dropdown widget can show a name, and a corresponding value (long string ID) can be passed into a script.
I would like to have two text entry boxes and a button with a task to add the value of those text boxes as a key/value constraint.
I have tried to adapt the replacing/get constraints sample .grid file to get this to work, I feel like I am close, but I cannot figure out why when it adds the new constraint, it is not reading the existing key values for the constraints with .getValue().
Any input would be greatly appreciated
<abs contexttype="opengear" gridsize="20" id="_top"> <meta> <params> <param access="1" constraintstrict="false" constrainttype="STRING_STRING_CHOICE" maxlength="0" name="Sheet_ID" oid="Sheet_ID" type="STRING" value="0" widget="default"> <constraint key="1JeBg61Gep2n2OQh7aUiNV_R9Bb8">DEFAULT</constraint> <constraint key="15v8TMXWxkY">SHOW A</constraint> <constraint key="1Kg_jNIhsHh-hoUA-hXm7MEWyofXcU">SHOW B</constraint> </param> <param access="1" maxlength="0" name="new_ID" oid="new_ID" type="STRING" value="123456789" widget="text"/> <param access="1" maxlength="0" name="new_Name" oid="new_Name" type="STRING" value="testing" widget="text"/> </params> </meta> <param expand="true" height="120" left="180" oid="Sheet_ID" showlabel="false" top="60" widget="combo" width="400"/> <button buttontype="push" height="60" left="940" name="ADD SHOW" top="260" width="160"> <task tasktype="ogscript">var existValues = params.getConstraint('Sheet_ID').getChoices();var newName = params.getValue('new_Name', 0);var newID = params.getValue('new_ID',0);var newValues = []var numList = params.getConstraint("Sheet_ID");var choices = numList.getChoices();for (var i = 0; i < choices.length; i++) { newValues.push({"key": choices[i].getValue(), "value": choices[i].getName()});}newValues.push({"key": newID, "value": newName}); var newCon = params.createStringStringChoiceConstraint(newValues);params.replaceConstraint('Sheet_ID', newCon);</task> </button><param expand="true" height="40" left="200" oid="new_ID" showlabel="false" top="280" widget="combo" width="360"/> <param expand="true" height="40" left="760" oid="new_Name" showlabel="false" top="280" width="120"/> <label height="20" left="60" name="New Google Sheet ID" style="txt-align:west" top="280" width="140"/> <label height="20" left="620" name="Show Name" style="txt-align:west;" top="280" width="160"/> </abs>
------------------------------
Evan Aaron
Engineer
Game Creek Video
------------------------------