Flow Designer - how to use the resulted list of Look up Records action in subsequent Lookups ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2023 05:25 AM
hello,
for a housekeeping process, I need to get all records which are not verified more than 6 months in following steps:
1) 1st Lookup - get all records not verified more than 6 months (checking the "sys_created on" or "u_verified on" values)
2) For each record from 1st lookup: Send notification to the owner to verify the record
3) Wait 10 days
4) 2nd Lookup - get all the records from the 1st Lookup, for which the "u_verified_on" is not updated
5) For each record from 2nd lookup: Send notification to the owner to verify the record
I know the "Look up Records" with conditions is working only on Tables, but for the 2nd lookup I have to work with a list of records (result from 1st lookup).
Can anyone advise me how to do it ?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2023 11:49 PM - edited ‎12-29-2023 11:51 PM
Hi @Kiril Dimov
In ServiceNow Flow Designer, you can achieve this by using subflows to handle the subsequent lookups. Here's a step-by-step guide on how to implement the described housekeeping process:
1. First Lookup
- Use the "Look up Records" action to get all records not verified for more than 6 months.
- Save the result in a variable, let's call it `firstLookupResult`.
2. For Each Record in the First Lookup Result
- Use the "For Each" action to iterate over each record in `firstLookupResult`.
- Inside the loop:
- Send a notification to the owner to verify the record.
- Add a "Wait" action for 10 days.
3. Second Lookup
- Create a subflow for the second lookup. This subflow will take a record as an input parameter.
- Inside the subflow:
- Use the "Look up Records" action to get the record from the first lookup result.
- Check if the "u_verified_on" field is not updated.
- Save the result in a variable, let's call it `secondLookupResult`.
4. For Each Record in the Second Lookup Result
- Use the "For Each" action to iterate over each record in `secondLookupResult`.
- Inside the loop:
- Send a notification to the owner to verify the record.
Putting it All Together
- In your main flow, after the 10-day wait in the first lookup loop, call the subflow for the second lookup and pass the current record as a parameter.
- The second lookup subflow will then handle the lookup and notification for each record.
This approach allows you to work with the list of records from the first lookup in a structured way. Subflows are useful for encapsulating reusable logic and help keep your main flow clean.
Remember to handle errors appropriately and consider adding additional checks and conditions based on your specific requirements.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2023 01:14 AM
thanks for the reply, using sub-flow is a valid option.In your point 2, I think "wait 10 days" should not be in the loop, as if we have 10 records from 1st lookup, that loop will last 100 days to complete. I did not the logic for the 2nd lookup - it should run inside the loop "for each" from 1st lookup or start from the root of the main flow? In 2nd lookup if I use the flow variable with saved records from 1st lookup it won't allow setting conditions, like to check if "u_verified_on" date older than 6 months, it works only if a Table is provided, not variable.
I was thinking of using one flow variable and every time I do lookup, to override the initial list, by removing the verified records.
I was also thinking of some custom action (scripted) to work with the lookup result, but let me try the sub-flow option first.
Thanks! Happy New Year !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 02:00 AM
I fixed it myself. Using additional condition in the lookup: Sys ID is one of result from 1st Lookup. That way I'll work only with the initial list of results.