How to capture the value of caller's department

Alon Grod
Tera Expert

Hi,

 I have this script include and im trying to get the callers's department but i see the system logs that im not getting anything. I tried to type inc.caller_id.department but it didnt work as well. How can I capture the reference field department from the caller id on incident table?

 

var OperUtil = Class.create();
OperUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {

isService: function() {

var inc = new GlideRecord("incident");
inc.addQuery('active=true');
inc.query();
while (inc.next()) {
var gdt = new GlideDateTime(inc.sys_created_on);
var date = gdt.getDate();

gs.log('inc dept: '+ inc.caller_id.department.getDisplayValue());

var oper = new GlideRecord('u_operational_activity');
oper.addEncodedQuery('u_departments=' + inc.caller_id.department + '^u_from_date<=' + date + '^u_to_date>=' + date);
oper.query();
return oper.hasNext();

}
},

type: 'OperUtil'
});

 

Screen Shot 2023-01-16 at 13.48.11.png

6 REPLIES 6

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Alon Grod ,

 

Use below code :- I have added encodedQuery instead of just add query. Also commented remaining part just to  check we are getting log or not. In my instance I'm getting department from below script.

var OperUtil = Class.create();
OperUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    isService: function() {

        var inc = new GlideRecord("incident");
        inc.addEncodedQuery('active=true');
        inc.query();
        while (inc.next()) {
            var gdt = new GlideDateTime(inc.sys_created_on);
            var date = gdt.getDate();

            gs.log('inc dept: ' + inc.caller_id.department.getDisplayValue());

//             var oper = new GlideRecord('u_operational_activity');
//             oper.addEncodedQuery('u_departments=' + inc.caller_id.department + '^u_from_date<=' + date + '^u_to_date>=' + date);
//             oper.query();
//             return oper.hasNext();

        }
    },

    type: 'OperUtil'
});

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

@Gunjan Kiratkar is there any way that we can send the script include the caller's department and the created on from the incident table and then he will use them to do the checking and then he will return true/false to the client script?

@Gunjan Kiratkar instead of looping through all incidents. the goal is to make a field on the incident table mandatory using script include and client script

Hi @Alon Grod ,

I'm not sure what you want to achieve from above scripts.

If you want to pass the department from script include to client script then return it as below

 

return inc.caller_id.department.getDisplayValue();

 

 And from client script pass the incident number to the script include so that you can easily find that incident in script include using encoded query.

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy