- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2018 07:14 AM
Hi All,
Consider the below scenario and help me in solving it
I have created a "List" type field in Incident form and it is referenced to "User" table.
I added a user to the "List" type field in Incident form. After that. I deleted the same user in "User" table . Now i am able to see a sys_id in the "List" type field in Incident form.
So help me like, if i delete the a user in "User" table, it should also delete its value in the referenced fields("List" type field in Incident form) and it should not display any sys_id.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 10:20 PM
Let's see if this helps,
(function executeRule(current, previous /*null when async*/) {
var userid = current.sys_id;
var useridlist = [];
var inc = new GlideRecord('incident');
inc.addQuery('u_user_list','CONTAINS',userid);
inc.query();
while(inc.next()){
var userlist = inc.getValue('u_user_list');
var users = userlist.split(",");
for(var i =0; i<users.length; i++){
if(userid.toString() != users[i].toString())
useridlist.push(users[i].toString());
}
inc.u_user_list = useridlist;
inc.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 09:41 PM
Check if this helps,
(function executeRule(current, previous /*null when async*/) {
var userid = current.sys_id;
var useridlist = [];
var inc = new GlideRecord('incident');
inc.addQuery('u_user_list','CONTAINS',userid);
inc.query();
while(inc.next()){
var userlist = inc.getValue('u_user_list');
var users = userlist.split(",");
for(var i =0; i<users.length; i++){
if(userid.indexOf(users[i]) > -1)
useridlist.push(users[i]);
}
inc.u_user_list = useridlist;
inc.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 09:57 PM
Hi Shishir,
I am getting error like
org.mozilla.javascript.NativeArray@721ae2
Thanks & Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 10:02 PM
try with ,,
inc.u_user_list = useridlist.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 10:15 PM
Hi Shishir,
I have in total 3 users in the GlideList. I am deleting the 3rd user in the List.
After this script , I am able to see the sys_id of deleted user only and the remaining two users have been removed
Thanks & Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 10:20 PM
Let's see if this helps,
(function executeRule(current, previous /*null when async*/) {
var userid = current.sys_id;
var useridlist = [];
var inc = new GlideRecord('incident');
inc.addQuery('u_user_list','CONTAINS',userid);
inc.query();
while(inc.next()){
var userlist = inc.getValue('u_user_list');
var users = userlist.split(",");
for(var i =0; i<users.length; i++){
if(userid.toString() != users[i].toString())
useridlist.push(users[i].toString());
}
inc.u_user_list = useridlist;
inc.update();
}
})(current, previous);