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

Joe B2
Giga Guru

This may work:

  1. Do a Lookup Records query against the table
  2. Use the Count data pill from the lookup records query in the first function and drop that into the Max Results setting on the next lookup?

But if i do loop up records i still need to define max? and i understood that if max is not defined so default value is 1000.

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. 

Just wanted to follow up and see if this worked for you or if you encountered any other issues/issues with the solution?