Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How to add and remove values in list type field using flow

SS1510
Tera Expert

I have a requirement, there is a table in which i have a field called record _user of list type, i want to add user in the field  using flow without removing other users and also if i remove any user through flow only that user should remove.
Does anyone have idea how to do that?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@SS1510 

See below working example for adding

enhance it for removal

var currentWatchList = fd_data.trigger.current.watch_list.toString().split(',');
currentWatchList.push(fd_data.flow_var.usertoaddremove.toString());
return currentWatchList.toString();

For removal use this script

var currentWatchList = fd_data.trigger.current.watch_list.toString().split(',');

var indexToRemove = currentWatchList.indexOf(fd_data.flow_var.usertoaddremove.toString());

currentWatchList.splice(indexToRemove, 1);

return currentWatchList.toString();

Output: Working for addition

list field add user flow designer.gif

Output: Working for removal

list field remove user flow designer.gif

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@SS1510 

you can use flow variable of type String and store sysId of the user which needs to be added/removed

Then use "Set Flow Variables" flow logic and use script to append/remove only that user by accessing the field value.

Then use "Update Record" flow action to update that list type of field with the Flow variable

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Ankur Bawiskar
Tera Patron

@SS1510 

See below working example for adding

enhance it for removal

var currentWatchList = fd_data.trigger.current.watch_list.toString().split(',');
currentWatchList.push(fd_data.flow_var.usertoaddremove.toString());
return currentWatchList.toString();

For removal use this script

var currentWatchList = fd_data.trigger.current.watch_list.toString().split(',');

var indexToRemove = currentWatchList.indexOf(fd_data.flow_var.usertoaddremove.toString());

currentWatchList.splice(indexToRemove, 1);

return currentWatchList.toString();

Output: Working for addition

list field add user flow designer.gif

Output: Working for removal

list field remove user flow designer.gif

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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