How do you change a field's value to the None choice in script?

stinky2nine
Tera Contributor

http://wiki.servicenow.com/index.php?title=Customizing_Choice_Lists#Values_Associated_with_.22None.22_option

says that the "None" option does not have a sys_choice record associated with it. I tried setting the field to following values but they all failed to become None.
- '' (empty string)
- '0'
- 0
- null

10 REPLIES 10

CapaJC
ServiceNow Employee
ServiceNow Employee

With GlideRecord (like in a Business Rule), I've always just used the empty string. Maybe something else is going on that's setting the value back? If you're using Business Rules for what you're doing, you can try using the "Debug Business Rules (Detailed)" module before performing the action. The output on screen will show you which rules are setting which fields to which values.

http://wiki.servicenow.com/index.php?title=Debugging_Tools_Best_Practices#Server-Side_Debugging


Interesting, the table in question is sys_email_account where type is smtp. I want to set authentication field to none. There is no business rule in this table that touches this field.


CapaJC
ServiceNow Employee
ServiceNow Employee

I ran this script in Scripts - Background, and it blanked out the authentication field where type was "SMTP".

[code]
doit();
function doit() {
var gr = new GlideRecord('sys_email_account');
gr.addQuery("type", "smtp");
gr.query();
while (gr.next()) {
gr.authentication = "";
gr.update();
}
}
[code]


I am doing the exact same thing except for creating a new record. For example,



var gr = new GlideRecord('sys_email_account');
gr.initialize();
gr.name = 'test';
gr.type = 'smtp';
gr.server = 'smtp.local';
gr.enable_tls = true;
gr.authentication = '';
gr.password = '';
gr.active = false;
gr.insert();


The authentication type is still password.


CapaJC
ServiceNow Employee
ServiceNow Employee

If a field has a default value, that default value gets applied on insert if it currently has no value. No way around that.

So if there's a default value, you could remove it in the Dictionary.