How to create an arrary or JSON variable in Flow Designer and use it?

gjz
Mega Sage

I have a business requirement to check the User table weekly and find all users who haven't logged into ServiceNow in the last 45, 90 and 120 days.  Based on the number of days (45 - 90, 90 - 120, 120+) a notification and task needs to be created.  I'm using the last_login field on sys_user in Flow Designer to find all users who meet the criteria.

 

Because a different notification/task is created based on how long the user hasn't logged in, it necessitates I query the User table three times in the same flow, which seems excessive to me.  I would like to query the table once and store the user's sys_id and number of days (using a custom date diff action) into a variable.  Then, in a For Each loop I will read the variable and create the correct notification/task based on the 45, 90, 120 day criteria.

 

My question is - how can I do that?  I need a 2 dimensional array to store the data from the User table, but I don't see an array as a flow variable type.  My next thought was I could use a JSON flow variable, but I've never used JSON variables and I don't know how to create them or use them in a flow.

 

Can someone help me with this, please?  TIA!

3 REPLIES 3

AnveshKumar M
Tera Sage
Tera Sage

Hi @gjz ,

You need to write custom script action where you can query and store the record sys_id and number of days. And the array will be returned as an output of that script action. 

 

Then you can use this output in flow for loop to iterate over each record.

Thanks,
Anvesh

Thanks AnveshKumar for the suggestion.  However, I really do want to know how to create and use a JSON flow variable.  Do you know how?

nschombu
Tera Contributor

The lack of documentation on the JSON flow variable has me stumped as well.