- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 07:37 PM
Hello,
I am not able to set value for the priority field based on the reference field(department). I created two fields department and priority. department is reference and priority is choice.
If i select customer support. priority should be changed to critical. if we select IT, priority should be changed to High.
My script is
var ge= g_form.getReference('group');
if(ge.name == 'IT')
{
g_form.setValue('priority','2');
g_form.setMandatory('emergency');
}
Can anyone help me out??
Thanks,
NItesh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 07:53 PM
You have to get reference like below
function onChange(control, oldValue, newValue, isLoading) {
var caller = g_form.getReference('group', doAlert); // doAlert is our callback function
}
function doAlert(caller) { //reference is passed into callback as first arguments
if (caller.name == 'IT')
{
g_form.setValue('priority','2');
g_form.setMandatory('emergency');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 07:53 PM
You have to get reference like below
function onChange(control, oldValue, newValue, isLoading) {
var caller = g_form.getReference('group', doAlert); // doAlert is our callback function
}
function doAlert(caller) { //reference is passed into callback as first arguments
if (caller.name == 'IT')
{
g_form.setValue('priority','2');
g_form.setMandatory('emergency');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 08:04 PM
Does this solution need to be scalable?
For example, are you using IT as one example of a department that requires this behaviour, or is there more?
It is also important to note that ServiceNow do not recommend the use of getReference anymore, even with a callback.
The recommended approach is to use GlideAjax.
Consider refactoring.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 09:51 PM
From a maintenance perspective, I highly recommend taking a look at doing this with Data Lookups to define the rules in data rather than code. It also prevents you from colliding with client scripts that may already be trying to set the value based on the data lookup rules.
Data Lookup and Record Matching Support - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 09:56 PM
Yeah, that's where I was going with the 'scalable' part
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022