clear the sys_id in GlideList field

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.

9 REPLIES 9

Hi,



Use the following code.



var Gruser = new GlideRecord("incident");


Gruser.addQuery('sys_id','sys_idvalue');


Gruser.query();




var currentuser = gs.getUserID();// for current user


gs.print("currentuser sys_id:"+currentuser );


while(Gruser.next()){


var usrlist = Gruser.getValue('watch_list');


var users = usrlist.split(",");


const index = users.indexOf(currentuser );




if (index > -1) {


      users.splice(index, 1);


}




Gruser.watch_list=users.join();


Gruser.update();


}




Hit Correct/ Endorsers/ Helpful/ Like depending on the impact of the response




Lakshmaiah Dumpala


Hi lakshmaiah,



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


Hi,



(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()); // See the link how to user the getValue() function



https://developer.servicenow.com/app.do#!/api_doc?v=istanbul&id=r_ScopedGlideRecordGetValue_String



If you want to get the display values of user use the inc.getDisplayValue('userlist');



Let me know what is field type of u_user_list.



gs.addInfoMessage(userlist);/// Are you getting the user list here ?



var users = userlist.split(",");


var index = users.toString().indexOf(userid);


gs.addInfoMessage(index);



if(index>-1){


users.splice(index,33); // Why are you hard coding index value here


}



inc.u_user_list = users.join();


inc.update();


gs.addInfoMessage(userlist);



//gs.addInfoMessage(inc.sys_id); */



}



})(current, previous);




Hit ✅Correct, ��Helpful, or ��Like, Endorsers depending on the impact of the response


@Lakshmaiah Dumpala


Hi DNC,



Still if you have issues keep posting the question in community.



Thanks,


Lakshmaiah Dumpala