assign catalog item using a script while using the Create Catalog Task action in flow designer

Efra Pruneda
Mega Guru

I am creating a subflow that is intended to be used from different catalog items.  this subflow receives the following input parameters: reference to the ritm record, reference to the assignment group and reference to the item (sc_cat_item).

while using the Create Catalog Task action in the subflow, I was able to use the first two parameters: ritm to the requested item field and the assignment group field. but I don't see how I can assign the catalog item. there is no script option there. It will be awesome if someone can help me to figure out how to use the third parameter and dynamically assign the item to allow this subflow to be 100% reusable.

thank you all in advance.

Efra

1 ACCEPTED SOLUTION

Ok, I have a better understanding of exactly what you're trying to accomplish. I don't think what you're trying to do is possible in the way that you're wanting.

JoeS1_0-1685030683511.png

Like you noted the Template Catalog Item field is not scriptable it's set to a single static value, even if it were scriptable how would you choose the variables to move from the Available to the Selected side so that they're displayed on the Catalog Task?

 

There is an option though, you could not populate the Catalog item field so that way you wouldn't have to worry about which variables to show or not. On the variable record itself is a field called "global" that is not on the variable form. This field, if set to true, will automatically display the variable on the RITM and the SCTASK records. This gives you the option to re-use your subflow but on the individual variable record control what displays and what doesn't on the SCTASK.

JoeS1_1-1685031143888.pngJoeS1_2-1685031154846.pngJoeS1_3-1685031167815.png

 

 

View solution in original post

10 REPLIES 10

What servicenow release are you on? I am on Tokyo patch 8 and I am not seeing the global checkbox under availability.  here are the four checkboxes I have. my guess is that one of these is equivalent to your global. I have all four check boxes checked for every variable in my test catalog item. I will play with these and report back. thank you!

availability options.PNG

It's not on the form be default, I had to add it to my form and I just added it to the Availability section.

 

Joe,

I was able to add the global field to the variable definition form. once I set all the variables in the catalog item to global = true I was able to see the variables in the sc_task even when the create catalog task has the template catalog item field blank in the subflow! I think this is going to work!!!

Amit Gujarathi
Giga Sage
Giga Sage

Hi @Efra Pruneda ,
I trust you are doing great.

To dynamically assign the catalog item in your subflow and make it reusable, you can utilize a script to achieve this. Here's an example of how you can use the third parameter, "reference to the item (sc_cat_item)," and assign it dynamically:

  1. In your subflow, locate the "Create Catalog Task" action where you want to assign the catalog item.
  2. Add a new script step before the "Create Catalog Task" action. This script will fetch the catalog item based on the provided reference.

 

// Fetch the catalog item record based on the provided reference
var itemRef = current.variables.item; // Assuming 'item' is the input variable name for the catalog item reference
var itemGR = new GlideRecord('sc_cat_item');
if (itemGR.get(itemRef)) {
  // Set the catalog item field in the 'Create Catalog Task' action
  current.cat_item = itemGR.sys_id;
} else {
  gs.error('Catalog item not found for the provided reference: ' + itemRef);
}

 


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Amit,

thank you for your reply! this is what I was hoping for!

but I have questions before I can test it

1. what is the best action to use to run a script in flow designer? I am using set flow variables not because I want  to assign a value to a variable, but it will give me a chance to run any script. do let me know your recommendation.

2. if I run the script before the create catalog task action (step 2 from your response), how do I tie the script to an action that has not run? in other words, how does flow designer knows that current.cat_item = so and so is related to the create catalog task action?