How do you change a field's value to the None choice in script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2013 12:32 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2013 01:16 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2013 01:40 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2013 02:00 PM
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]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2013 07:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2013 08:31 AM
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.