Flow Designer GlideRecord vs Client Script

Corey Allgood
Kilo Contributor

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.

1 ACCEPTED SOLUTION

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

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

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!

Thanks for the reference sheet! I'll take a look through that now!