Get Catalog Variable Record Count in Flow Designer & Pass Count Value to Flow Variable

WazzaJC
Tera Expert

Get Catalog Variable Record Count in Flow Designer & Pass Count Value to Flow Variable

Dear ServiceNow Community colleagues, I am having a challenge on how to achieve this.

 

In Flow Designer, I need to Get a Catalog Variable, which contains an array of Sys_ID's - I then want to Count the number of Sys_ID's in that Get Catalog Variable action, and pass the Count (Integer) value to a separate Flow Variable, called 'Count'.

 

What is the fd_data script that I need to use, in order to get the Count from the catalog variable multi-line text (string) field and place that value in the 'Count' Flow Variable ?

 

My Catalog Variable that I will use the 'Get Catalog Variable' function within my Flow, is called 'access_selected_for_removal_sys_id_summary'

 

The Flow Variable that I need to post the Count Records value to, is called 'Count'

 

I have attached a screenshot, which for example shows 2 x Sys_IDs in the 'access_selected_for_removal_sys_id_summary' variable - I need the script to count these Sys ID's and place the count (integer) value in the 'Count' Flow Variable.

 

The Display Name of the variable is : AWS Access/Role (s) selected for Removal - Sys ID's summary with the corresponding field value name : ''access_selected_for_removal_sys_id_summary''.

 

Many thanks for any help/guidance on this, greatly appreciated, I would really appreciate how I can solution this.

 

Kind Regards.

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@WazzaJC 

it's an easy task

1) Define a flow variable of type Integer

2) use Get Catalog Variables Flow Action and ensure you add your variable from left to right bucket

3) then use Set Flow variable logic and set the value using inline script

// give the name of your variable here 'my_datetime'

var count = fd_data._1__get_catalog_variables.my_datetime.toString().split(',').length;
return count;

check this and enhance

flow variable logic.gif

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

View solution in original post

@WazzaJC 

after comma there is empty string so it's giving count as 2

so logically it's 2 count

You can enhance it further to get the correct count

something like this

var sysIdArray = fd_data._1__get_catalog_variables.access_selected_for_removal_sys_id_summary.toString().split(',');
var filteredArray = sysIdArray.filter(function(sysId) {
        return sysId.trim() !== '';
    });
return filteredArray.length;

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

View solution in original post

5 REPLIES 5

@Ankur Bawiskar this is excellent Ankur ! It works now perfectly and elegantly, as a solution. Thank you for taking the time to help me with this, greatly appreciated kind sir. 🙂