Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Jim Coyne
Kilo Patron
Part of the Tips 'N Tricks" series.

 

We all should know that if we want to set (or change) the default value of a field, we simply have to go to the field's Dictionary Entry and set the "Default" field to whatever it is we need.  Can be a simple string or even a snippet of JavaScript.

 

However, that can cause you issues or extra work during upgrades.  Because you've changed the record, you now own it.  ServiceNow will NOT automatically upgrade the record if there are any changes to it in the future, so it ends up being listed as a "Skipped" record, which you should be reviewing.  You're going to have enough of them, no need to add anymore if you can avoid them.

 

One way to do it is to create a Dictionary Override.  However, that only works if the field you want to change is for a child table in a table hierarchy (e.g. you want to default the "State" field to something for an Incident record).

What about fields on a table that do not support Dictionary Overrides?  The "Script" field on the Record Producers table for instance.  I like to enclose my scripts within an IIFE (or S-EAF) template to protect my code and protect other code from mine 😉

 

So how can I change the default value of the "Script" field without giving myself extra work in the future?  Well, that would be with the use of automatically applied templates.  These are normal form Templates with a slight twist.  To have the Templates automatically applied when you create a new record through the UI, simply set the "Name" of the Template to be the same as the table name (not the display name).  Automatic templates are always global - they ignore the "User" and "Group" fields on the Template form.  Automatic templates only apply when manually creating a record through the UI and do NOT apply to records created by Business Rules, UI Actions, etc...

 

So, to have the "Script" field populated with my IIFE template, I simply create a new Template on the Record Producer table, set the "Name" field to "sc_cat_item_producer" and add my script template for the "Script" field:

 

find_real_file.png

 

Now when I create a new Record Producer, the "Script" field is automatically set for me:

 

find_real_file.png

 

Am I lazy?  Yeah, maybe.  Could have used a Syntax Editor Macro instead.  But the nice thing about it is I know that anyone else creating Record Producers will now have the same IIFE template applied.  And I don't have to worry about the field's Dictionary Entry record on future upgrades.

1 Comment