The CreatorCon Call for Content is officially open! Get started here.

Flow Designer script help for update record

matt_a
Kilo Guru

Please could some assist with the following script im wanting to use in flow designer?

var aData = fd_data._6__look_up_records.records;
var aArr = [];
var msg = "This is a test";

if(!aArr.length){
while (aData.next()) {
    aArr.push(aData.getDisplayValue());
}
return aArr.join(', ')
}
else{
    return msg;
};

Following a lookup of records in the flow, I want to push the content of the array into the additional comments. So if the lookup returns items, they successfully post to the comments. But my else isnt working.

Probably something simple im not doing right, but equally, the flow script often throws me!!

1 ACCEPTED SOLUTION

Voona Rohila
Mega Patron
Mega Patron

Hi matt

Try this logic to return else part if there are no records.

var aData = fd_data._6__look_up_records.records;
var aArr = [];
var msg = "This is a test";
​while (aData.next()) {
aArr.push(aData.getDisplayValue());
}
if(aArr.length){
return aArr.join(', ');
}
else
return msg;

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

1 REPLY 1

Voona Rohila
Mega Patron
Mega Patron

Hi matt

Try this logic to return else part if there are no records.

var aData = fd_data._6__look_up_records.records;
var aArr = [];
var msg = "This is a test";
​while (aData.next()) {
aArr.push(aData.getDisplayValue());
}
if(aArr.length){
return aArr.join(', ');
}
else
return msg;

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP