
|
Until today, there is no way to modify the value of catalog variables in Flow Designer using an Action.
But with the help of a small self-developed Flow Action this functionality can be implemented quickly, and this article shows how to do that.
At Flow Designer create a new Action "Update Catalog Variable" and then configure it as follows.
|
|
|
Inputs

We need mandatory 3 input variables for this Action: the Requested Item, which holds all catalog variables and the name, as well as the new value.
Script Step
Insert a script step with the following parts:
Input

Script
Enter the following code into the script field:
(function execute(inputs, outputs) {
try {
var variables = inputs.requested_item.variables.getElements();
for (var i = 0; i < variables.length; i++) {
var question = variables[i].getQuestion();
if (question.getName() == inputs.variable_name) {
question.setValue(inputs.variable_value);
}
}
inputs.requested_item.update();
outputs.state = 'success';
}
catch (e) {
gs.error(e);
outputs.state = 'error';
}
})(inputs, outputs);
As you can see, there is a try-catch block to protect the flow from unexpected errors. Furthermore, the script returns an output variable "state", which helps the calling Flow to react on the respective behavior.
Outputs
The mentioned "state" output has to be configured at this section:

Testing and Publishing
You can easily test that Action with a given Requested Item. And then don't forget to publish your new Action!
Integration into a Flow
After setting the "Service Catalog" trigger you can configure the new Action:

Note:
It is not necessary to insert a "Get Catalog Variables" action, as the new Action updates the Requested Item directly
Optionally, you can query the status after executing the Action and branch accordingly:
