- 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-17-2018 08:27 AM
It's not working for other users too
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2018 11:41 AM
I'm afraid the cascade delete rules only apply on reference fields and not GlideList fields, after diving a bit deeper and experimenting.
The only thing you can do is build your own script (for more information, see the following KB & script examples: ServiceNow KB: Interacting with a Glide List field (KB0596181) / Reference a Glide list from a business rule ) or even better; don't delete any user because of history tracking you'd like to keep within the organization.
Kind regards,
Stijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 06:53 PM
Hi stijn,
Could you please help me with the below script
(function executeRule(current, previous /*null when async*/) {
var userid = current.sys_id;
gs.addInfoMessage(userid);
var inc = new GlideRecord('incident');
inc.addQuery('u_user_list','CONTAINS',userid);
inc.query();
while(inc.next()){
gs.addInfoMessage(inc.number);
var userlist = inc.getValue('u_user_list'.toString());
gs.addInfoMessage(userlist);
var users = userlist.split(",");
var index = users.toString().indexOf(userid);
gs.addInfoMessage(index);
if(index>-1){
users.splice(index,33);
}
inc.u_user_list = users.join();
inc.update();
gs.addInfoMessage(userlist);
//gs.addInfoMessage(inc.sys_id); */
}
})(current, previous);
i am facing issues with script in bold format
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 08:39 PM
Are you able to print: gs.addInfoMessage(userlist); ??
what are you trying to achieve?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 09:22 PM
Are you able to print: gs.addInfoMessage(userlist); ??
yes, it is displaying comma separated sys_id's
what are you trying to achieve?
I want to clear the sys_id in GlideList, when its value has been deleted in original table