Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Add user to list collector without removing the ones before

F_bio Santos
Kilo Sage

Hi everyone, I created a custom field on "task" table which will get the current assigned user everytime it changes without removing the one that is already there, I not sure on how to do this. Im thinking about trying a Business rule on "task" table with:

Before > Update

 

var assignedTO = current.getValue('assigned_to');
var listField = current.getValue('listColletorUsers');


listField  = current.listColletorUsers + current.assigned_to;

 

 

1 ACCEPTED SOLUTION

Update the script as follows.

 

var assignedTO = current.getValue('assigned_to');
var listField = current.getValue('listColletorUsers');
if(listField.indexOf(assignedTO)==-1){
listField  =listField+',' + assignedTO;
current.setValue('listColletorUsers',listField);
}

Hope this works for you.

View solution in original post

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@F_bio Santos List collector is nothing but a comma separated string of sys_ids. Please check if the following script works.

 

var assignedTO = current.getValue('assigned_to');
var listField = current.getValue('listColletorUsers');
listField  =listField+',' + assignedTO;
current.setValue('listColletorUsers',listField);

 

Hope this helps.

Hi @Sandeep Rajput it worked, but for some reason it is getting the user 3 times. Could it be because I have:

before > update 

Assigned_to > changes 

Update the script as follows.

 

var assignedTO = current.getValue('assigned_to');
var listField = current.getValue('listColletorUsers');
if(listField.indexOf(assignedTO)==-1){
listField  =listField+',' + assignedTO;
current.setValue('listColletorUsers',listField);
}

Hope this works for you.

Amit Verma
Kilo Patron
Kilo Patron

Hi @F_bio Santos 

 

Please have a look on the below post :

https://www.servicenow.com/community/developer-forum/business-rule-to-add-items-to-a-list-collector-...

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.