- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 07:29 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 10:09 PM
update as this
line 26
arr = gr.u_impacted_users.toString().split(',');
line 28
gr.setValue('u_impacted_users', arr.toString());
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 08:54 PM
Hi
I've observed two things here -
1. change line 28, gr.setValue('u_impacted_users',arr.join(','));
2. change line number 26 => arr = gr.getValue("u_impacted_users").toString().split(',');
Regards,
Snehangshu Sarkar
Please mark my answer as correct if it resolves your query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 09:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 09:51 PM
Hi
Remove gs.setValue(arr) from your script.
Use the below script. It's tested, should work.
if(action == 'resolve'){
var arr = [];
arr = gr.getValue('u_impacted_users').toString().split(',');
arr.push(<userId>); // if you have any user to add it, replace <userId> with the user sys_id
gr.setValue('u_impacted_users',arr);
gr.update();
}
Regards,
Snehangshu Sarkar
Please mark my answer as correct if it resolves your query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 10:00 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 09:41 PM
Hi Aeden,
Is u_impacted_users a comma delimited string? If so, change the following lines.
Change the following lines
var arr = [];
arr = gr.getValue('u_impacted_users');
arr.push(userID);
gr.setValue(arr);
gr.update();
To
arr = gr.getValue('u_impacted_users');
gr.setValue('u_impacted_users', arr + ',' + userID);
gr.update();
