Call Client callable script include at BR

Lucky1
Tera Guru

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

 

1 ACCEPTED SOLUTION

@Lucky1 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

18 REPLIES 18

J Siva
Tera Sage

Hi @Lucky1 
Follow the below community post with similar requirement.
https://www.servicenow.com/community/itsm-forum/call-client-callable-script-include-from-business-ru...

Regards,
Siva

Hello SIva,

 

My script include name is: Inc_scripts    (this is Client callable)

functions inside it are:

1. getImpact:function( ){

 

},

 

2. getUrgency:function( ){

 

},

 

Now can you please tell me how to call these two functions in my BR.

 

 

Regards,

Lucky

Mohit Kaushik
Mega Sage
Mega Sage

Hi @Lucky1 as the link shared by @J Siva will solve your query, however, you need to modify your function in the script include.

But I would suggest you to create data lookup rules in your instance to handle these cases, You can define the matrix like on what conditions you want the values to to be set to the Priority field. And with that it should automatically make the changes and this should work from any where.  And this can be done just with the configurations.

https://www.servicenow.com/docs/bundle/yokohama-platform-administration/page/administer/field-admini...

https://www.servicenow.com/docs/bundle/yokohama-platform-administration/page/administer/task-table/c...

https://www.servicenow.com/docs/bundle/yokohama-platform-administration/page/administer/field-admini...

Above links will help you understand more about data lookup rules and how to create them.

 

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Ankur Bawiskar
Tera Patron
Tera Patron

@Lucky1 

you can use same function of that client callable script include and make it call from client side GlideAjax and also from any server side.

the way how parameters are passed & accessed will vary and need to be tweaked.

this syntax should help you

   getIncidents: function(problemId) {
        var probSysId = JSUtil.nil(problemId) ? this.getParameter('sysparm_sys_id') : problemId;
		// now the probSysId can contain value either coming from ajax or from any server side code
			
    },

Client Callable and Server Callable Script Includes (in one!) 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader