- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2022 02:02 AM
TLDR; Is it possible to dynamically add variables to tasks inside a Subflow? Ex. via an input variable?
Hello everyone 🙂
What I was basically hoping would be to ex. have an input source in the sub flow, which I could then simply add to a task. The closest I've come is this:
Allow flow designers to dynamically set field values - https://docs.servicenow.com/bundle/rome-servicenow-platform/page/administer/flow-designer/task/templ...
The issue, is that the "task variable template" doesn't really seem to allow adding variables to the task, only modify existing fields. It doesn't even seem like I can modify variables already added to task via a "template catalog item".
Any thoughts? 🙂
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2022 09:27 AM
Short answer: Yes, with a custom action that runs a script step.
I believe the flow designer "task variable template" is more about making those variable available/visible on the Catalog Task. In order to actually update the variable value you would need to create a simple custom action. The trick is (I believe, but could be mistaken on this point) you actually update the variable on the RITM. I'll put a very basic example of how you can do this below, but this is only for simple variables and to get you started
Step 1 for custom action: Create inputs:
- RITM that holds the variables (reference to the Requested Items [sc_req_item] table)
- Variable Name -the name (not question) of the variable to update
- Variable Value - the new value for the variable
Step 2 for custom action: Create Script step:
- This step does the work documented here
- With planning and some work, you could even update MVRS with the details from that document
- Pull the 3 inputs from step 1 into the
- Execute code to update the variable:
inputs.req_item.variables[inputs.variable_name] = inputs.variable_value; inputs.req_item.update();
You can of course make this more robust to go and pull the variable anew to ensure the new value was set, and the throw an error as needed, etc. But again, this should get you started and will hopefully help!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2022 09:27 AM
Short answer: Yes, with a custom action that runs a script step.
I believe the flow designer "task variable template" is more about making those variable available/visible on the Catalog Task. In order to actually update the variable value you would need to create a simple custom action. The trick is (I believe, but could be mistaken on this point) you actually update the variable on the RITM. I'll put a very basic example of how you can do this below, but this is only for simple variables and to get you started
Step 1 for custom action: Create inputs:
- RITM that holds the variables (reference to the Requested Items [sc_req_item] table)
- Variable Name -the name (not question) of the variable to update
- Variable Value - the new value for the variable
Step 2 for custom action: Create Script step:
- This step does the work documented here
- With planning and some work, you could even update MVRS with the details from that document
- Pull the 3 inputs from step 1 into the
- Execute code to update the variable:
inputs.req_item.variables[inputs.variable_name] = inputs.variable_value; inputs.req_item.update();
You can of course make this more robust to go and pull the variable anew to ensure the new value was set, and the throw an error as needed, etc. But again, this should get you started and will hopefully help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2022 01:22 AM
Thanks for the reply Chris, and the well described walkthrough 🙂
I basically wanted a way to create tasks without having to reference a template object (cat item), allowing easier reuse.
I ended up with an action that takes following inputs ...
- Requested item, from which I fetch variables, parent task etc.
- Template value, transfeering task fields.
- String, which can be used to select variables (comma separated, includes all ritm vars if left empty).
1. Create task, sets field variables using template values and set requested item (parent) to ritm. Note, no wait.
2. Script, fetches variables off ritm (either all or the names included in input string), then creates them for the task.
3. Finally a wait, since scripts have to be run on the task, the wait is deferred until last.
Output can be whatever you want, most likely the task record.
/Cheers