- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 04:41 AM
Hello all,
I have created a Script Include and written two functions in it.
one for when Impact on Incident changes, and the other one is when urgency changes.
So, I have created two on Change client scripts and calling the corresponding functions in it using Glide Ajax.
So, now whenever we change the Impact or Urgency, on the form, I am setting up the Priority using these two On Change client scripts.
Now, if the Incident is created from Portal side, and if the Impact is 1 and Urgency is 1, then I need to set the Priority to 1.
So, how can I call these two functions in the BR script?
Regards,
Lucky
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 06:09 AM
update as this and it should work from both the side i.e. client and server (BR)
getImpact: function(impact, urgency, id) {
var impact = JSUtil.nil(impact) ? this.getParameter('sysparm_impact') : impact;
var urgency = JSUtil.nil(urgency) ? this.getParameter('sysparm_urgency') : urgency;
var id = JSUtil.nil(id) ? this.getParameter('sysparm_id') : id;
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', id);
gr.query();
if (gr.next()) {
if (urgency == 1 && impact == 1) {
return 1;
} else if {
urgency == 1 && impact == 2) {
return 2;
}
}
},
Now you can call it like this from server side
var priority = current.priority;
var urgency = current.urgency;
var impact = current.impact;
if(urgency == 1 && impact == 1){
current.setValue('priority', 1);
}
var id = current.sys_id;
var val = new ScriptIncludeName().getImpact(impact, urgency, id);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 05:34 AM
Hello ANkur,
Already, the both functions are called in On change CS, using GLide AJax and they are working fine at Clien side,
Now I want to make use of two functions a Business rule.
My script include name is: Inc_scripts (this is Client callable)
functions inside it are:
1. getImpact:function( ){
},
2. getUrgency:function( ){
},
Please help
Regards,
Lucky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 05:46 AM
syntax to call from server side is this i.e. from Business rule
new scriptIncludeName().getImpact(sendValueHere);
new scriptIncludeName().getUrgency(sendValueHere);
But the functions need to be enhanced in script include as well so that it works from both side client and server
So you will have to update like this in script include
getImpact: function(impact) {
var impact = JSUtil.nil(impact) ? this.getParameter('sysparm_impact') : impact;
// now the probSysId can contain value either coming from ajax or from any server side code
},
getUrgency: function(urgency) {
var impact = JSUtil.nil(urgency) ? this.getParameter('sysparm_urgency') : urgency;
// now the probSysId can contain value either coming from ajax or from any server side code
},
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 06:05 AM
Hi ANkur,
It's a bit confusing for me.
Can you please correct my code.
My Script Include:
Name: Inc_scripts
Client callable : true
Script:
getImpact:function( ){
var impact = this.getParameter('sysparm_impact');
var urgency = this.getParameter('sysparm_urgency');
var id = this.getParameter('sysparm_id'); //here I am getting the Inc sys_id
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', id);
gr.query();
if(gr.next()){
if(urgency == 1 && impact == 1){
return 1;
}
else if{urgency == 1 && impact == 2){
return 2;
}
}
}.
////////////////////////////////////////////////////////////////////////////////////////////////////
My Business Rule:
Name: Set Priority
Before update
Script:
var priority = current.priority;
var urgency = current.urgency;
var impact = current.impact;
if(urgency == 1 && impact == 1){
current.setValue('priority', 1);
}
........................................................... and so on
At on Change client script, I am getting the answer and setting the value to priority.
Regards,
Lucky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 06:09 AM
update as this and it should work from both the side i.e. client and server (BR)
getImpact: function(impact, urgency, id) {
var impact = JSUtil.nil(impact) ? this.getParameter('sysparm_impact') : impact;
var urgency = JSUtil.nil(urgency) ? this.getParameter('sysparm_urgency') : urgency;
var id = JSUtil.nil(id) ? this.getParameter('sysparm_id') : id;
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', id);
gr.query();
if (gr.next()) {
if (urgency == 1 && impact == 1) {
return 1;
} else if {
urgency == 1 && impact == 2) {
return 2;
}
}
},
Now you can call it like this from server side
var priority = current.priority;
var urgency = current.urgency;
var impact = current.impact;
if(urgency == 1 && impact == 1){
current.setValue('priority', 1);
}
var id = current.sys_id;
var val = new ScriptIncludeName().getImpact(impact, urgency, id);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 06:38 AM
Hello Ankur,
It is not working in BR.
I submitted a record producer which creates Incident. So, while submitting I have given Impact as 1 and Urgency as 1, so the Priority has to be set as 1 but it set as 4, (so not working).
Please help me in correct my code:
My Script Include:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
My Business RUle:
Regards,
Lucky