The CreatorCon Call for Content is officially open! Get started here.

Flow designer - count all records in table

Eli Guttman
Tera Guru

Hi,

In flow designer, i need to query and update multiple records in a table. when using look up action, need to define the max results (if not defined it is set to  1000). i would like to dynamically define the max results by counting the number of records in the table.

Is there a flow designer action to count all records in a table or this would need to be done using a script / custom action?

1 ACCEPTED SOLUTION

So another alternative is to 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 grCount = new GlideRecord('TABLENAME');
grCount.addEncodedQuery('QUERY HERE');
grCount.query();

return grCount.getRowCount();

 

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 query.

 

Hopefully that does the trick. Not had need to do this myself but this is how I would tackle it. 

View solution in original post

7 REPLIES 7

Hi Tera,

 

Thanks for you suggestion - that option indeed work. Eventually i created an action that does something similar. By doing it with an action, I was able to reuse it in several sub flows i needed.

 

Thanks again!

Brilliant - glad it worked.

romank
Tera Contributor

I would consider using GlideAggregate as using GlideRecord just to get the number of records with getRowCount is considered bad practice (performance)

See:
Counting with GlideAggregate (servicenow.com)