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.

How to add users to a list with Server Script?

Aeden Frost
Tera Contributor

Hi Everyone,

 

I am trying to add some functionality which adds users to a list through the service portal, however in the Server Script I had used gr.setValue() 

Unfortunately this deletes all other entries to the list and replaces it with the one user, what would be the best way to add users without removing previous users?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Aeden Frost 

update as this

line 26

arr = gr.u_impacted_users.toString().split(',');

line 28

gr.setValue('u_impacted_users', arr.toString());

Regards
Ankur

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

View solution in original post

19 REPLIES 19

Thank you very much for the advice Hitoshi, unfortunately it still isn't working. I'm just trying to add user names to a glide_list field 

find_real_file.png

Ankur Bawiskar
Tera Patron
Tera Patron

@Aeden Frost 

update as this

line 26

arr = gr.u_impacted_users.toString().split(',');

line 28

gr.setValue('u_impacted_users', arr.toString());

Regards
Ankur

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

Thank you very much Ankur, it's now working as intended, I am posting a screenshot of the final script so that anyone else searching for the answer can see the finished block of code.

find_real_file.png

@Aeden Frost 

I could see you marked my response as correct earlier and now it is not.

Would you mind marking my response as correct since my script worked for you.

Regards
Ankur

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

Sorry Ankur, I had just changed it to the finished script in case anyone else was searching for the answer for the full script.

I changed it back now.