Dynamically Add Variables to A Task (Flow Designer)

Simon Ohle
Kilo Guru

Hey,

 

I want to build a flow that I can use dynamically on multiple catalog items that should only create a task.

When using the "Create Catalog Task" I need to select a specific Catalog Item to specify the variables.

 

I simply want all Variables from the sc_req_item also to be visible on my task. Is there a way to create this dynamically?

Cheers,

Simon

 

#flowdesigner

1 ACCEPTED SOLUTION

Sebastian R_
Kilo Sage

Hi @Simon Ohle ,

this is actually quite simple with a custom action.

Background: The assignment of variables to a catalog task is done in table "sc_item_variables_task", so you only have to add the variables here as records.

 

Sample script which you can use in a flow action with a "catalog_task" as input

(function execute(inputs, outputs) {
    var sTaskID = inputs.catalog_task.getValue('sys_id');
    var grRITM = inputs.catalog_task.parent.getRefRecord();

    var aVariables = grRITM.variables.getElements();

    aVariables.forEach(function (grVariable) {
        grTaskVariable = new GlideRecord('sc_item_variables_task');
        grTaskVariable.task = sTaskID;
        grTaskVariable.variable = grVariable.getQuestion().id;
        grTaskVariable.insert();
    })
})(inputs, outputs);

In your flow you have to do the following:

  1. Create Catalog Task (Wait = false)
  2. Call your flow action "Add Variables to Catalog Task"
  3. Call action "Wait for Condition" which condition Catalog Task.Active = false

SebastianR__0-1700664332292.png

 

View solution in original post

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

@Simon Ohle 

Currently not possible.

you need to have separate flow associated to each catalog item.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Simon Ohle 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Rahul Goyal
Tera Contributor

Hi Simon,

As per my understanding, you have multiple catalog Items and need to create a main flow then create task based on the Inputs from the catalog. 

Did you try use of Dynamic Flows in your main flow and then that dynamic flow will call your respective Subflows of catalog item and create task there.

For second line you mentioned, to see all variables in Task, Can you mark all your variables as True for Global Field in the Catalog Item. This will make your variables visible on Task.

Let me know if that helps.

Marking it as Global also works. Sebastians Solutions was the one I was looking for. Thank you for your response!