Replace Key/Value String Constraint

Hey everybody! So I’ve gotten familiar with the syntax and process to read and replace choice constraints for INT and STRING choice constraints. What I am trying to do is replace the choice constraints of a string parameter with a key/value choice constraint where both the key and the value are strings.

The ultimate goal I am trying to accomplish is to get a list of materials from an Xpression published field and create a parameter from it, but rather than having the user see the whole material name, I want the “Key” of that choice to be a shorthand version of the material name, and the “Value” be the actual material name that I can send back to Xpression.

I think I can also accomplish this with two separate INT choice constraints by creating them simultaneously and when the user chooses an option on the “Key” parameter, then just set the “Value” parameter to the same index. But if I can accomplish something with one parameter instead of two that would be preferable.

Let me know if anyone has any ideas. Thank you!

You should be able to replace the string/string constraint. Here is a panel that shows the different ways you can replace the different types of constraints.

If you look at the second one String Key/Value Constraint it should be what you are looking for.

One Two Three Four Five zero ten twenty thirty forty zero one two var choices = new Array(); choices[0] = 'One'; choices[1] = 'Two'; choices[2] = 'Three'; choices[3] = 'Four'; choices[4] = 'Five';

var newCon = params.createStringChoiceConstraint(choices);
params.replaceConstraint(“choiceString”, newCon);


var choices = new Array();
choices[0] = ‘Un’;
choices[1] = ‘Deux’;
choices[2] = ‘Trois’;
choices[3] = ‘Quatre’;
choices[4] = ‘Cinq’;

var newCon = params.createStringChoiceConstraint(choices);
params.replaceConstraint(“choiceString”, newCon);

var newValues = [] newValues.push({"key": "1", "value": "one"}); newValues.push({"key": "2", "value": "two"}); newValues.push({"key": "4", "value": "four"}); newValues.push({"key": "8", "value": "eight"}); newValues.push({"key": "16", "value": "sixteen"});

var newCon = params.createStringStringChoiceConstraint(newValues);
params.replaceConstraint(“keyChoiceString”, newCon);


var newValues =
newValues.push({“key”: “0”, “value”: “zero”});
newValues.push({“key”: “10”, “value”: “ten”});
newValues.push({“key”: “20”, “value”: “twenty”});
newValues.push({“key”: “30”, “value”: “thirty”});
newValues.push({“key”: “40”, “value”: “forty”});

var newCon = params.createStringStringChoiceConstraint(newValues);
params.replaceConstraint(“keyChoiceString”, newCon);






var choices = new Array();
choices[0] = ‘A’;
choices[1] = ‘B’;
choices[2] = ‘C’;

var choiceConstraint = params.createIntChoiceConstraint(choices);
params.replaceConstraint(“choiceInt”, choiceConstraint);


var choices = new Array();
choices[0] = ‘one’;
choices[1] = ‘two’;
choices[2] = ‘three’;
choices[3] = ‘four’;
choices[4] = ‘five’;
choices[5] = ‘six’;

var choiceConstraint = params.createIntChoiceConstraint(choices);
params.replaceConstraint(“choiceInt”, choiceConstraint);

var rConstraint = params.createIntRangeConstraint(1,10); params.replaceConstraint("rangeInt", rConstraint); var rConstraint = params.createIntRangeConstraint(1,50,5); params.replaceConstraint("rangeInt", rConstraint); var rConstraint = params.createIntRangeConstraint(0,100,1000,1100,10); params.replaceConstraint("rangeInt", rConstraint);

Perfect, that’s exactly what I was looking for. Thank you Ben!