The Dictionary Entry Records & Default Values
In ServiceNow, you can default field values to improve automation efforts in your environment.
Every field on every table, is a Dictionary Entry in ServiceNow.
When you’re looking at a form, that form is contained of fields. Those fields are all configurable as “columns” on a table. Every one of those fields, is easily referenced back to the Dictionary Entry [sys_dictionary] table.
There are several important fields on the Dictionary entry record.
These fields include whether or not the field is active, whether it’s mandatory, read-only, what table it lives on, certain attributes, etc.
One of these very important fields is the “Default Value” field. The “Default Value” field is under the “Default Value” tab.
In the Default Value field, you can use JavaScript to set the value of that field.
Returning A Dynamic Default Value
For example, it probably makes sense to set the “Caller” field as the user that is submitting an incident.
You can even go further than this. You can write queries in a business rule for example, that returns a value to automatically set in that field.
That’s exactly what the out of box “caller_id” field on the Incident table does. It calls a business rule function and returns the users value, to automatically populate.
You can either use a “Dynamic default value” which calls a function in a business rule, or you can just use some JavaScript to set the value directly.
It really depends on whether or not you want to return a value immediately, or if you need to interact with a table in ServiceNow – and return a value from a query.
Here is what the referenced record looks like, that connects the dictionary entry to the business rule.
The “Script” and the “Reference Script” values need to be populated in order for this to work properly.
You need to populate the “Script” with the full function name of the function that’s returning a value in the business rule. Make sure the check the “Active” checkbox too.
Below is what ServiceNow uses to get the current user, to populate the Caller on every incident.
So here is a benefit of using a query, to return a value. It’s a more custom way to get a value, if a single line of JavaScript won’t work.
Return A Value Using JavaScript or GlideSystem
This is the more common use case, in my opinion.
It’s more frequent that you’re going to write a piece of JavaScript as a default value, than to write a business rule to return a value from query.
If you’re familiar with the ServiceNow Glide System, you can utilize that to auto-populate a value with it.
For example, take any Date/Time field in ServiceNow that tracks the “Opened at” value.
You don’t want a user to modify this value, nor do you want the user to ever populate this value.
It should be auto populated one single time and then never updated again.
To accomplish this, you don’t need to write a client script or business rule. You can just set a Default Value that will work every time. Each time it’s referenced, when a record is created, the system calculates the default value at the dictionary level.
The above value will return the current date and time, and set that as the value of the field – automatically.
When you’re using JavaScript to set a field value, you just need to prepend the Javascript, with “javascript:” {enter JavaScript here}
For example, you’d use the following:
Take the above example of wanting to set a value for the “opened_by” user on table.
We will always want to set the “opened_by” field to be the value of the user that is submitting the record, on insert.
So to capture that value and set it, we use the following:
javascript: gs.getUserID();
This auto populates the value in the field, without any need for manual intervention.
There are endless opportunities when using JavaScript and the GlideSystem to populate field values.
Let us know how you’re using Default Values at the dictionary level below.
Hi! How about page load time in millisecond, how do we do it in default value? Say default value every time the page is loaded should be like 1680167597087. Thanks in advance.
ServiceNow doesn’t have an easy way of doing something like this, and if it were to be accomplished, it wouldn’t be done with a Default Value at the dictionary level. There is a page load indicator in the bottom right hand side of every page in the native UI. I’d probably start there to see what’s causing a slow instance.
How do I add something like “Record has been updated by ” javascript: gs.getUserDisplayName();
When a journal entry is updated in ServiceNow, for a comment/worknote, it already shows who performed the action. So I don’t think you’d need or want to add it again/twice. You’d probably want to do this in a Business Rule, and not a Default Value.
But to add it as a default value, you’d modify what you have a bit: