Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How do you clear a reference fields value for current.fieldname?

DrewW
Mega Sage

How do you clear a reference fields value for current.fieldname? I found some docs to indicate that I should do the below but it does not work. Can anyone offer any help?

var clearValue;
current.u_affected_item = clearValue;
current.update();

Docs I am refering to.
http://wiki.service-now.com/index.php?title=Resetting_Reference_Fields

9 REPLIES 9

Hmm...I just tried this on /demo and the empty quotes method worked just fine. The other two methods didn't work however.

current.u_affected_value = '';
current.update();


Did you do this when creating a new incident?

I just changed the code and it still is not clearing the field. I have tryed several ways and so far this is the ONLY way that it would work for me...? I just do not get it....

answer = current.insert();
if(current.u_affected_item){
var tci = new GlideRecord('task_ci');
tci.initialize();
tci.ci_item = current.u_affected_item;
tci.task = answer;
tci.insert();

var i = new GlideRecord('incident');
i.addQuery('sys_id', answer);
i.query();
while (i.next()) {
i.u_affected_item = '';
i.update();
}
}

gs.include('ActionUtils');
var au = new ActionUtils();
au.postInsert(current);


Not applicable

The "Resetting reference fields" example method is a client script, whereas this is a business rule:

http://wiki.service-now.com/index.php?title=Setting_a_GlideRecord_Variable_to_Null


current.u_affected_value = 'NULL';
current.update();


Ok, so I change the script to the below and it did not work either. For what ever reason I have to go get the glide record and set the value to null. I can not just do current.u_affected_item = "NULL"; it just does not work in this case. I still do not understand why but I have something that works. Thanks everyone for the input/help.

answer = current.insert();
if(current.u_affected_item){
var tci = new GlideRecord('task_ci');
tci.initialize();
tci.ci_item = current.u_affected_item;
tci.task = answer;
tci.insert();

// var i = new GlideRecord('incident');
// i.addQuery('sys_id', answer);
// i.query();
// while (i.next()) {
// i.u_affected_item = '';
// i.update();
// }
current.u_affected_item = "NULL";
current.update();
}

gs.include('ActionUtils');
var au = new ActionUtils();
au.postInsert(current);


anuguajay
Kilo Explorer

nice