Comment
GlideEdward
Tera Explorer

@James Fricker 's solution is great, and very elegant.

 

We have used it in conjunction with Flow Designer's inbuilt error handler to catch unexpected inputs and other errors related to updating catalog variables.

 

(function execute(inputs, outputs) {
    /* A bad argument for variable_name would cause an error when we try to update the variable
    E.g if the variable doesn't exist on the RITM
    So we exit the function here if that's the case. */
    if (!inputs.requested_item.variables.hasOwnProperty(inputs.variable_name)) {
	    throw "Variable " + inputs.variable_name + " does not exist on " + inputs.requested_item.number;
    }
    
    /* We are assured that the variable exists, however the update might still fail due to permissions or 
    incompatible typings, so we use a try/catch block to gracefully handle those outcomes. */
    try {
	    inputs.requested_item.variables[inputs.variable_name].setValue(inputs.variable_value);
	    inputs.requested_item.update();
    } catch (error) {
	    throw "Unable to update variable " + inputs.variable_name + " on " + inputs.requested_item.number + ": " + error;
    }
})(inputs, outputs);

Using the error handler, means we don't need the originally proposed output.state variable:

GlideEdward_0-1770635236723.png