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

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.


You should start a new POST when you have a question. This one has been marked as 'Answered' so may NOT get many responses.

Is there possibly another script or UI policy setting the field back. The UI Policy will set the value on the screen, the Database value is NOT changed until the record is 'SAVED'.

It looks like your syntax is correct. You can also try using g_form.setValue('u_sensitive_data','');


try unchecking reversible.


Thanks Doug. Unchecking the Reverse if False did not work; however the following change was made which works:

OLD

function onCondition() {
g_form.clearValue('u_sensitive_data');
}

NEW

function onCondition() {
g_form.setValue('u_sensitive_data', '');
}