How do I blank a field from a Business Rule or Script Include..?

DarkAvenger
Kilo Expert

Hi all

I have been trying to create a Business Rule or a Script Include that is executed from a Reference Qual attribute on a reference field.

Besides returning the query this code should also set another (related) field to blank when-ever it is executed. The point with this is mainly to set that other field (also a reference field) to blank every time the user clicks on the magnifier on the reference field (this is a requirement from the users).

My problem is that I am having a problem finding the right syntax for setting the field to blank.

I have e.g. tried a simple expression like this one below, on both a Business Rule and Script Include:


     current.u_location = '';


(the field that should be set to blank is called u_location and it is a reference field)

Besides that I have tried g_form.clearValue('u_location') and also constructions like this:

     var uLocBlankVal;
     g_form.setValue('u_location', uLocBlankVal);


(the idea with above script is to set the field value to an undefined variable, as explained here: https://wiki.servicenow.com/index.php?title=Resetting_Reference_Fields)

None of these have so far set the u_location field to blank, however.

Is field blanking even possible from a Script Include or a Business Rule?

TIA
8 REPLIES 8

randrews
Tera Guru

i agree with the previous poster to acomplish something similiar i used an on change client script with the line

g_form.clearValue('v_server_patching');

and it worked fine... is there a reason it has to be a BR or a script include?

If i understand correctly a BR runes when it loads/updates the database.. so won't take affect till they try to save the record.. and a script include wouldn't run after it was loaded either.


Miguel Caldero3
Mega Expert

It sounds to me that you want to do this on client script. The idea will be when they make a change to a field then the other one gets clear out.


DarkAvenger
Kilo Expert

There was actually an onChange Client Script for the field and I was able to modify that to clear the other field.


billi_lumley
ServiceNow Employee
ServiceNow Employee

Hi! I have a question in regards to clearing a value. I've created a UI Policy to clear the contents of a field based on a condition. Works great, however if the condition is then reversed (i.e., state changes BACK to New), then the contents reappear. Is there a way to clear the contents and keep it that way even if the condition was reversed?

State changes to Complete
function onCondition() {
g_form.clearValue('u_sensitive_data');
}

State change back to New from Complete
The data reappears.