how to clear the sys_ID

Chaitanya Chowd
Kilo Expert

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.

find_real_file.png

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.

find_real_file.png

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.  

1 ACCEPTED SOLUTION

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);


View solution in original post

25 REPLIES 25

Stijn Verhulst3
Kilo Guru

Hi,



Does this happen when you set Clear and -- None -- on your cascade delete rule of your list field? (Configure cascade delete rules ) Never really paid attention to it before...



Kind regards,



Stijn


Hi,



I tried 'Clear' and "'none'-default". It is not working.



It's clearing the reference but not the sys_id.



Thanks & Regards,


Chaitanya


Gowrisankar Sat
Tera Guru

Glidelist references to list of sys_id's from user table if you select multiple users from the list. Make sure the reference cascade rule is set to clear, which is --none-- by default which makes the sys_id of the user record deleted stay as a sys_id on the list.



Try restoring the user from deleted records, change the setting on dictionary level and delete again, i knew this is frustrating


Hi,



I have set the reference cascade rule to 'Clear', restored the user and then deleted the record. It is not working.



It's clearing the reference but not the sys_id.



Thanks & Regards,


Chaitanya