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

@Lucky1 

you didn't share what debugging did you perform?

I answered your question on how to make sure same function can be called from client side i.e. Ajax and also from server side

Next part you can debug by adding gs.info() statements

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

Hello Ankur,

 

Lucky1_0-1745506284669.png

 

The first log is coming up but the second log is not coming

 

 

 

Regards,

Lucky

 

@Lucky1 

In that case it means you are unable to call it

I will suggest you to check the script include is in which scope and check by adding logs in the script include function

There are numerous blogs and articles on how to effectively debug your scripts.

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

Hello Ankur,

 

I will check it and come back. Thank you

 

Regards,

Lucky

@Lucky1 

I believe I have answered your original question on how to make sure same function can be called from client side i.e. Ajax and also from server side

Next part you can debug by adding gs.info() statements

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