- 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:47 PM
Lets try two things now,
add gs.info("check userid = "+userID); // in line 9 to check in script log statements(In app nav) if you have any value
In line 26. make some chnages:
arr = gr.getValue("u_impacted_users").toString().split(',');
Now it should work
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 09:06 PM
I checked the script log statements and it is returning a value, however the server script is still not adding the user to the list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 09:29 PM
Hi
change line 28, gr.setValue('u_impacted_users',arr.join(','));
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:41 PM
In line 10 you are querying the table,
But which record you are trying to update is not mentioned, do you have sys_id of the record which you want to update, that you have to add as well, as in
var gr = new GlideRecord("table_name");
gr.addQuery("sys_id","sys_id_of_the_Record");
gr.query():
while(gr.next()){
// add update statements for retrieving the array and setting the value
var arr = gr.getValue("u_impacted_users").toString().split(',');
arr.push(userid);
gr.setValue("field_name",arr);
gr.update()
}
}
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 10:06 PM
Can you confirm if you have checked this?
Aman Kumar
