Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get count of selected values in watchlist field using flow designer

ranjanak
Tera Contributor

Hi All,

 

I'm working in a requirement to capture the count of values in watchlist field using flow designer.

 

I tried using input type as array.string and array.object but its not working.

Any help is really appreciated.

Thanks 

1 ACCEPTED SOLUTION

Hemanth M1
Giga Sage
Giga Sage

Hi @ranjanak ,

 

Can you try flow variable (Integer type) and get the watchlist count as below

 

1.Declare flow variable integer type Integer

HemanthM1_0-1755191303853.png

2. Use set flow variable step

 

HemanthM1_1-1755191390769.png

 

3. Output

HemanthM1_2-1755191477114.png

 

 

HemanthM1_3-1755191513415.png

 

Hope this helps!

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

3 REPLIES 3

Hemanth M1
Giga Sage
Giga Sage

Hi @ranjanak ,

 

Can you try flow variable (Integer type) and get the watchlist count as below

 

1.Declare flow variable integer type Integer

HemanthM1_0-1755191303853.png

2. Use set flow variable step

 

HemanthM1_1-1755191390769.png

 

3. Output

HemanthM1_2-1755191477114.png

 

 

HemanthM1_3-1755191513415.png

 

Hope this helps!

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Hi @Hemanth M1 ,

Thanks for your help, I followed your steps and it is working.

Bhimashankar H
Mega Sage

Hi @ranjanak ,

 

The watchlist stores a comma separated list.

 

Use the existing record (Look up record) and compute the count with inline script when setting a variable.

  • Add “Set flow variables” (create an Integer variable like watchlistCount) or “Update record” to store the count somewhere.

  • In the value for watchlistCount, click the Script icon (fx) and try below script:

 

(function() {
  var s = (fd_data.current.watch_list || '').toString().trim();
  if (!s) return 0;
  // Remove empty entries and whitespace, then count
  var arr = s.split(',').map(function(x){return (x||'').trim();}).filter(function(x){return x;});
  return arr.length;
})();

 

 

Please go through below how to iterate watchlist in flow designer.

Add users to watchlist in fd 

 

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!