- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 01:15 PM
Hello,
I'm working on a Flow Designer action that is meant to pull a list of records from a GlideRecord and output the response to an array. It seems to be working with a caveat.
var company = inputs.company;
var contacts = [];
var grContacts = new GlideRecord(${CONTACTS_TABLE});
grContacts.addQuery(${COMPANY_FIELD}, company);
grContacts.query();
while (grContacts.next()) {
contacts.push(grContacts.${EMAIL});
}
The expected response (and the behavior I see running this identical code from a client script) would be:
["Me@no-reply.com","User1@no-reply.com","User2@no-reply.com"]
What I'm seeing in Flow Designer is actually that it iterates the number of times, but duplicates the value that number of times, so it would be:
["User2@no-reply.com","User2@no-reply.com","User2@no-reply.com"]
Could someone please tell me where I'm going wrong?
Thanks.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 02:13 PM
Lookup Records followed by a ForEach will iterate over the records and you can build the array into a Flow Variable.
My code did exactly what was suggested regarding the pass by reference issue, I used the toString() method to force it to be a string.
Another issue can be that you are not getting what you think with the grContact.${EMAIL}. How about like this:
var company = inputs.company;
var contacts = [];
var email = '';
var contacts = new GlideQuery(${CONTACTS_TABLE})
.where(${COMPANY_FIELD}, company)
.select(${EMAIL})
.map(function (contact) { return contact.${EMAIL}; })
.toArray();
GlideQuery is worth a look, it can do some pretty nifty things.
Please mark as correct/helpful if this helps.
Thanks,
Aoife
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 01:45 PM
It's likely an issue with pass by reference
When you push an item into your array, make sure it's a string:
grContacts.getValue('email')
or
grContacts.email.toString()
Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 01:54 PM
Thanks for the reference sheet! I'll take a look through that now!