- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 01:32 AM - edited 04-04-2025 01:37 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 01:57 AM
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
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 06:10 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 01:57 AM
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
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 03:59 AM
@Ankur Bawiskar thank you very much Ankur. This is excellent, it works perfectly for me, great solution and very straight forward! I always appreciate your help. Many thanks kind sir. 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 05:27 AM - edited 04-04-2025 05:58 AM
Hi @Ankur Bawiskar can I just ask one further question. I am wondering why it is giving me a Count = 2 in my case (please see screenshots attached), when there is only one Sys_ID.
I am expecting to see only a Count = 1, as there is only 1 Sys_ID. Please let me know thanks very much Ankur. I am using exactly your script you mentioned.
You will see for example, a further screenshot I just attached - when I have 3 x Sys_ID's, it is bringing back a 'Count' = 4. Is the script somehow counting " , " as a value, so it thinks there are 4 x values ?
I am just wondering how it is always counting an additional value , when there are only X number of Sys_ID's.
Thanks for any further advice/help Ankur.
And this is my script I am using :
var count = fd_data._1__get_catalog_variables.access_selected_for_removal_sys_id_summary.toString().split(',').length;
return count;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 06:10 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader