- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2020 04:25 PM
Hi all,
I'm trying to update a variable on a task (or ritm) from within a flow in flow designer. What I have done is:
1. Create a custom action called "update TASK variable"
2. created three inputs, one reference type called task that references the sc_task table, one string type called variable, another string type called new value
3. run a simple script to update the variable typed in the inputs
(function execute(inputs, outputs) {
var task = new GlideRecord('sc_task');
task.get(inputs.task.getUniqueValue());
task.variables.inputs.variable = inputs.newValue;
task.update();
})(inputs, outputs);
This does not work because you can not use the inputs.variable in the line "task.variable.inputs.variable = inputs.newValue", I also tried "task.variables. + inputs.variable = inputs.newValue" but that does not work either. If I hard code it like "task.variables.approver_instructions = inputs.newValue" that works. I'd rather this action be re-usable for many flows, so I'd rather not hard code it as that makes it limited to a small scope of flows.
Is it possible to pass in a value in the inputs variables and dynamically set variables like this? Or am I out luck here.
Any thoughts / ideas / suggestions are appreciated!
Thanks!
- Derek
Solved! Go to Solution.
- Labels:
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 03:12 PM
Thanks for the reply, I have had the joy of figuring out the complicated way variables are saved in the past so fortunately what you're saying makes sense.
I didn't want to do it this way, but what I ended up doing is (bonus it's no code!)
1. do a look up record on the sc_item_option_mtom table where "Parent Item" is the RITM (use data pill). Optional AND "Dependent Item.Question.Name" IS ${name value}
2. another look up record on the sc_item_option table where "sys_id" is "Dependent Item.sys_id" of the record found in step 1.
That will return the sc_item_option record with the value of the variable that needs to be updated and can be used through the rest of the flow.
Not ideal, but works and is no code.
I really wish they'd have an OOB action item to update variables, maybe in a future release.
Thanks,
- Derek

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2020 04:56 PM
Hey Derek,
Interesting use case! To be honest it feels a bit not-ideal, but I won't judge 😉
If you haven't dug into how Variables, Tasks and RITMs work, this may be a bit of an exercise, but I think you can get your action working much better.
When a catalog item is created, you create Variables assigned to that item, which are stored on a table. There is then a Many 2 Many table, which stores INSTANCES of these variables, and their data. I can never remember exactly what all the tables are called, but start by looking at:
sc_item_option (instances of questions and their values)
item_option_new (what the variable definition is)
sc_item_option_mtom (reference between RITMs and Options)
Then, you may be able to pass in a variable, or an RITM and (possibly?) use a dynamic input/output to show the available variables and change them?
Anyway, I hope this gives you something to start looking into.
❤️ - Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 03:12 PM
Thanks for the reply, I have had the joy of figuring out the complicated way variables are saved in the past so fortunately what you're saying makes sense.
I didn't want to do it this way, but what I ended up doing is (bonus it's no code!)
1. do a look up record on the sc_item_option_mtom table where "Parent Item" is the RITM (use data pill). Optional AND "Dependent Item.Question.Name" IS ${name value}
2. another look up record on the sc_item_option table where "sys_id" is "Dependent Item.sys_id" of the record found in step 1.
That will return the sc_item_option record with the value of the variable that needs to be updated and can be used through the rest of the flow.
Not ideal, but works and is no code.
I really wish they'd have an OOB action item to update variables, maybe in a future release.
Thanks,
- Derek

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2020 01:36 AM
Great stuff Derek, thanks for posting this!
Following your ideas, I created a nice, clean, re-usable "Set Catalog Variable" subflow, now I can use it wherever I want. Its input variables are: Requested Item record (Reference), Variable name (String) and Variable value (String). The latter is String also, to make it as generic and re-usable as possible.
In case anyone reading this plans to do the same, one little thing to watch out for when using this subflow to set the value of a Duration type variable: you need to format the input value as "YYYY-MM-DD HH:mm:ss". When using a data pill of from another duration field/variable as input value, use the "Date to String" transform function with these settings:
Otherwise, your subflow will enter an empty value into the target Duration-type variable.
And as usual with subflows, embedding this subflow into your main flow as a Dynamic Flow call instead of a direct Subflow call is better in every possible way. For example, this way, you can control the behaviour of your main flow (whether it should abort or continue running, ignoring possible errors) in case your subflow fails to set the Variable value (e.g. because of ACL issues or because the Variable with that name does not exist).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2020 01:52 PM
Hello Gabor.
Great stuff. But when you created the subflow, apart from the Inputs, did you have to specify any outputs or actions? I am a bit new to flows, and I couldn't publish the flow with just the inputs specified. Screenshot attached.
What I am trying to do also, is set the variable read-only (or mandatory etc) via a subflow.
Thanks in advance, Mark S