- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
2 weeks ago
Background:
As a new Flow Designer user, coming from years of having more or less mastered workflows in the now legacy Workflow Editor, one of the first obstacles I ran into was how to use / re-use a flow for more than one Catalog Item, since Actions such as Get Catalog Variables and Create Catalog Task seem to be designed for use with one specific Catalog Item.
In our case we have a simple generic workflow that creates one Catalog Task, then closes when that task is closed. We need that task to display all of the Catalog Item variables, for whichever Catalog Item this is run against, and possibly override the default Catalog Task Assignment Group, Short Description, and/or Description.
The Problem:
In Workflow Editor, you simply move variables from the Available to Selected box at the bottom of the Catalog Task activity, once the Catalog Item has been associated with this workflow.
Flow Designer only permits one Catalog Item to be selected, so this same functionality is missing. We are also using Catalog Builder for some Citizen Developers, so the Flow will be used for Catalog Items that don't even exist yet.
Workflow Editor also contains an Advanced script section to override any of the Catalog Task fields such as Assignment group, Short description, Description... by using the 'current.variables...' syntax. Flow Designer uses data pills with some scripting overrides available, but only for certain fields and the syntax is not exactly straight-forward or documented.
A Solution:
The key to using a Flow for multiple Catalog Items is to avoid the Get Catalog Variables action, then work around any data pills for variables that would have been available, and use a Custom Action script to make the Catalog Task(s) show the variable(s).
Here's the beginning of a sample basic Flow that will create one Catalog Task which will show all of the variables for the Catalog Item that called it.
On the Create Catalog Task node, the key is to uncheck the Wait box, and do not select a Template Catalog Item or Catalog Variables.
To override the Assignment group with, let's say a variable named v_assignment_group from the Catalog Item, you can use the script on this field:
return fd_data.trigger.request_item.variables.v_assignment_group;
even though 'variables' does not appear in the prompt list as does fd_data, trigger, request_item... when building this return value, it works.
Don't be deterred by the Custom Action - this one is quite simple. In the Inputs section, create two to hold the RITM and SCTASK records that you'll pass in from the Flow.
Notice that I've made each Mandatory, so I won't forget to pass them in when I add the Action to the Flow.
Next click the blue + icon below Inputs on the left to add an Action - in this case you'll choose Script.
The Script step also needs two Input Variables created, the Value of which you will populate with data pills from the Input Variables section. The Script that does the magic looks like this:
(function execute(inputs, outputs) {
var scTaskID=inputs.sctask.getValue('sys_id');
var ritmVariables=inputs.ritm.variables.getElements();
ritmVariables.forEach(function(ritmVar) {
grTaskVar = new GlideRecord('sc_item_variables_task');
grTaskVar.newRecord();
grTaskVar.task=scTaskID;
grTaskVar.variable=ritmVar.getQuestion().id;
grTaskVar.insert();
})
})(inputs, outputs);
No script or action Outputs are needed in this case.
Back on the flow, when adding the Custom Action you populate the two Inputs with data pills from the Requested Item trigger and node 1 Catalog Task.
Then you may want to add a node to wait until the Catalog Task is closed before continuing.