- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2017 05:23 AM
Hi,
I have created new field "Upgrade Version" of type choice list(example: Geneva, Helsinki, Istanbul ) and Default value(Helsinki) with --None--.
The problem is for (Historical Data)old records also it is setting Helsinki as a value, we don't want to sent value for old records.
How can we achieve this? or Is it a ServiceNow Behaviour?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2017 09:02 AM
That's correct. Your update set is going to contain the latest changes to the dictionary entry and that's what's getting applied to test and prod (effectively negating the two step process I said before.)
If you cannot or don't want to do it that way, then a Fix Script is needed to "null out" the existing records immediately after applying the update set so only new records have the new default value.
That script would look something like this:
Standard disclaimer: The following code is untested, requires review and potential modifications.
(function () {
var rec = new GlideRecord('your_table'); //change your_table to your table name
rec.query();
while (rec.next()) {
rec.setValue('your_field', ''); // change your_field to your field
rec.autoSysFields(false); // do not update mod_count, updated time, etc.
rec.setWorflow(false); // do not run business rules or workflows
rec.update();
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2017 05:24 AM
Hi,
Create the field with no default value, then once the field is created, go back and set the default value. Existing records will have a value of none and new records will get the new default value as they are created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2017 07:27 AM
Thanks for your response Tomasi,
It is working as expected in Dev, when i move the code to QA then only it is happening like this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2017 08:26 AM
You'll need to do the two updates Chuck described in two separate update sets. In the same update set, it is only one record thus it has a default on-creation

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2017 09:02 AM
That's correct. Your update set is going to contain the latest changes to the dictionary entry and that's what's getting applied to test and prod (effectively negating the two step process I said before.)
If you cannot or don't want to do it that way, then a Fix Script is needed to "null out" the existing records immediately after applying the update set so only new records have the new default value.
That script would look something like this:
Standard disclaimer: The following code is untested, requires review and potential modifications.
(function () {
var rec = new GlideRecord('your_table'); //change your_table to your table name
rec.query();
while (rec.next()) {
rec.setValue('your_field', ''); // change your_field to your field
rec.autoSysFields(false); // do not update mod_count, updated time, etc.
rec.setWorflow(false); // do not run business rules or workflows
rec.update();
}
})();