- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 05:50 AM
Hi All
I have created a flow to add users to a list collector field, but I am now wanting to build another action to remove users from a list collector field
I have been on the community and found this script which I have adapted for my needs:-
(function execute(inputs, outputs) {
var sysId = 'inputs.sys'; //sys_id of the user to remove.
var list = new GlideRecord('cmn_location'); //tablename
list.get('name','Store Name');// pass the correct anem to get the record.
var arr = list.u_store_named_account_colleagues.split(','); //split the watch list values and put them in an array.
var idx = arr.indexOf(sysId); //get the index of sys_id of user you want to remove from watch list.
arr.splice(idx,1); // Remove the specific user from array. idx is the index from which you want to remove and '1' is the number of elements you want to remove.
list.u_store_named_account_colleagues= arr.join(','); // join the array and set the values back to watch list.
list.update(); // update the record
})(inputs, outputs);
The script works, but I want to make the action dynamic or useable in multiple scenerios, so I have the inputs to the action of
tablename
sys
fieldname
I wish to pass these variables into the script. I have successfully been able to pass the sysid into the script, but i cant get the tablename and fieldname to pass into the script without it erroring.
if i was to replace the script with these lines:-
var list = new GlideRecord('inputs.tablename');
and
var arr = list.'inputs.fieldname".split(',');
The script errors and says invalid table name, and that is when entering either "location" or "cmn_location" on the input
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 07:23 AM
No worries!
So for that bit on your glide record get it's a similar issue, you need it unquoted as if it's a variable so:
list.get('sys_id', inputs.record);// pass the correct record ID to get the record.
OR
list.get(inputs.record);// pass the correct record ID to get the record.
If you don't specify a field name with a get then it will assume that the value you are passing in is just a sys_id.
The bit with the square brackets I mentioned in my last response is just if you want to replace something in an object with a variable rather than hardcoding it (i.e when dot walking).
If I were on a SCTASK record then the below would output whatever field name I'd set:
var field_name = 'short_description';
gs.info(current.request_item[field_name]);
The above would grab the value from the parent (the request item)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 05:56 AM - edited 09-22-2023 06:42 AM
If I've read correctly then I think your issues probably lies with:
var arr = list.'inputs.fieldname'.split(',');
instead you want var arr = list[inputs.fieldname].split(',');
If that also happens to be line 5 in your script?
Edit:
You also don't want quotes around inputs.table_name, otherwise rather than treating it as a variable it will be an actual string/tablename called "inputs.table_name".
var list = new GlideRecord(inputs.tablename);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 06:53 AM
Hi Rhodri, thats brilliant thankyou, that now works. Although I have tried to make one of the other lines in the script dynaminc, by passing the sys_id of the record, rather than having the "name"
list.get('name','Store Name');
I have changed it to this:-
list.get('sys_id','[inputs. Record]');
but again it does not pass the sys_id into the script. I ahve also tried these aswell
list.get('sys_id', [inputs. Record]);
list.get('sys_id', 'inputs. Record');
Any ideas?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 07:23 AM
No worries!
So for that bit on your glide record get it's a similar issue, you need it unquoted as if it's a variable so:
list.get('sys_id', inputs.record);// pass the correct record ID to get the record.
OR
list.get(inputs.record);// pass the correct record ID to get the record.
If you don't specify a field name with a get then it will assume that the value you are passing in is just a sys_id.
The bit with the square brackets I mentioned in my last response is just if you want to replace something in an object with a variable rather than hardcoding it (i.e when dot walking).
If I were on a SCTASK record then the below would output whatever field name I'd set:
var field_name = 'short_description';
gs.info(current.request_item[field_name]);
The above would grab the value from the parent (the request item)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 08:08 AM
Your a star, works like a dream now, have a great weekend