- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 02:20 PM
Hi,
I'd like to understand how to work with the outputs of a Flow Designer action in a script.
Let's say I have a Lookup Records step (looking into sys_user), and in the following step, I have a field function which has to loop through the results of the previous step to create an array which can be used for further GlideRecord queries. This is where I'm stuck now.
An example script (which isn't working, btw):
var usrObjectList = {};
usrObjectList = fd_data._2__look_up_records.records;
gs.info('FlowStepTest Input: ' + JSON.stringify(usrObjectList));
var outputArray = [];
for (var user in usrObjectList){
outputArray.push(usrObjectList[user].sys_id);
gs.info('FlowStepTest single line: ' + usrObjectList[user].sys_id.toString());
}
gs.info('FlowStepTest output: ' + outputArray.toString());
return outputArray.toString();
In this experiment, I just want a comma separated list of sys_ids as an output, based on fd_data._2__look_up_records.
Can anyone give me a little hint?
Cheers!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 05:22 PM
hi
Instead of using a script to build an array, could you simply use flow designer to lookup up records on a table and use the results in another lookup?
for example:
If the above is not an option, the following may help you:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 05:22 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2020 12:09 AM
Hi,
Maybe I should tell a bit more about my scenario:
In the end, I want to use a slightly modified version of a script that allows determining the user with the lowest workload. There's some logic before (like looking into sys_user_has_role), providing me with a list of users that I want to feed into the script above. The script (which is already working) runs directly within an Update Record action, on the assigned_to field.
I'm already working with custom actions in the steps before, but I was hoping that I could somehow access an fd_data record list through a script directly in a field function and avoid creating another custom action.
I can't wait for Quebec. If all turns out as I expect, it should be possible to use a simple For Each loop to collect everything in a variable within the Flow.
So you don't see a chance to access the results of a Lookup Records action within a field function sctipt?
Br,
Kosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2020 05:25 AM
So if there is no further idea how to utilize the fd_data object, I'll close this question and give
Best regards!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2020 08:32 AM
Hi
I have an inline script working on Lookup Records output. Same as your requirement I think: it puts sys_id's of a previous Lookup Records action in an array.
It works basicly like any other GlideRecord while .next() loop.
An issue that might arise is that, like in my case, this .next() doesn't fetch the next record. This is problably when a previous For Each action has already looped through the output of the Lookup Records action. You say a number of other actions occur before this one in your Flow. So this might happen in your case too. Solution for this is to run the query again.
I've used this inline script as a condition for another Look Up Records action:
The inline script code:
var gr = fd_data._1__look_up_records.records;
var count = fd_data._1__look_up_records.count;
var sys_ids = [];
if(count > 0 && !gr.hasNext()){
// If a 'For Each' Action has been put in the parent Flow, before this Action,
// looping gr.next() won't do anything because it's already been looped through.
// We'll have to run the same query as the original 'Look Up Records' Action again.
gr = new GlideRecord(gr.getTableName());
gr.addEncodedQuery(gr.getEncodedQuery());
gr.query();
}
while(gr.next()){
sys_ids.push(gr.getValue('support_group'));
}
var sys_ids_array = sys_ids.join();
return "sys_idIN"+sys_ids_array+"";
You've probably moved on already since you posted this 😉 But if this has/could've helped, please let me know!
Best regards