Flow Designer Script to remove certain Items

Vasu2
Tera Contributor
 
10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@Vasu2 

Please share screenshots and what's your exact business requirement

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Viraj Hudlikar
Giga Sage

@Vasu2  It will be great if you share your question with little more details then only we will be able to help you.

Also, what have you tried from your side? What is technical blocker for you?

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

Hello @Vasu2 

 

Your code logic would be something to this

var res =;
var desc = fd_data.trigger.current.description.toString();
//assuming the record is the trigger and field is description feel free to update them
//test string '{"Rank 1":["user_id1"],"Rank 6":["user_id2"],"Rank 26":["user_id3"] }'
desc = JSON.parse(desc);
var hasRankGreaterThan25 = false;
var defaultUserID = 'YOUR_DEFAULT_USER_ID'; // Replace with the actual default user ID

for (var rankKey in desc) {
    if (desc.hasOwnProperty(rankKey)) {
        var tempAr = rankKey.split(' ');
        if (tempAr.length > 1) {
            var index1 = tempAr[1];
            var index1Int = parseInt(index1);
            if (index1 && !isNaN(index1Int)) {
                if (index1Int < 25) {
                    res = res.concat(desc[rankKey]);
                } else if (index1Int >= 25) {
                    hasRankGreaterThan25 = true;
                }
            }
        }
    }
}

// Remove duplicate user IDs
res = [...new Set(res)];

if (hasRankGreaterThan25) {
    res.push(defaultUserID);
}

return res.join(',');

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards

Viraj Hudlikar.

Hi @Viraj Hudlikar ,

getting error in Line1 and also in this below line of code 

res = [...new Set(res)];

Line 1 error

Vasu2_1-1742496166613.png