Count Group members In Flow

Tyler Johnson
Tera Expert

Is it possible to query the current total of group members in a specific group? For example im trying to figure out a way to incorporate a counter inside of flow designer. If the current count of a group is less than 100 as an example it would proceed with the next step under the flow. IF it is more it will go to a seperate approval. This would be handy for keeping tabs on your itil counts as we automate the assignment of the roles. Issue is that it can go over our allotted amount and thats why trying to incorporate a counter in the flow.

 

1 ACCEPTED SOLUTION

James Chun
Kilo Patron

Hey @Tyler Johnson,

 

You can do this with without any coding in Flow designer.

Use the 'Look up records' (note the plural here) activity, e.g.

JamesChun_0-1710284065317.png

And use the 'If' Flow logic like below:

JamesChun_1-1710284095588.png

 

Hope it helps, cheers

 

 

View solution in original post

3 REPLIES 3

Sumanth16
Kilo Patron

Hi @Tyler Johnson ,

 

use a flow variable and set this using a script:

 

  1. Define a new flow variable. This could be called anything but for the sake of clarity I will use recordCount and set it as an integer
  2. Create a flow action to Set Flow Variables and select your newly created variable from the list
  3. In the data column press the Toggle for scripting button and use the below code

 

 

 

var grp = new GlideRecord('sys_user_grmember');
grp.addQuery("group", current.sys_id);
grp.query();

if( grp.getRowCount() >100){
retunr true;

}
else if(grp.getRowCount() <100){
return false
}

 

 

This will query the intended table with whatever query you set to get a count. The return line then populates the flow variable recordCount with the number of records. You can then use this data pill for the Max Records on your Lookup Records.

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

James Chun
Kilo Patron

Hey @Tyler Johnson,

 

You can do this with without any coding in Flow designer.

Use the 'Look up records' (note the plural here) activity, e.g.

JamesChun_0-1710284065317.png

And use the 'If' Flow logic like below:

JamesChun_1-1710284095588.png

 

Hope it helps, cheers

 

 

how do you list all users that are part of the group using this logic