The CreatorCon Call for Content is officially open! Get started here.

Help with reference qualifier calling script include

dvelloriy
Kilo Sage

Hello Community,

We have a requirement to filter assignment groups on HR cases bases on coe security policies.

I have updated the reference qual (dictionary override on sn_hr_core_case table) and created a client callible script include however its not working.

Can someone please advise?

 

Reference qual: 

javascript : new sn_hr_core.HRAssignmentFilterUtil().getHRService(current.hr_service);

 

script include: 

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

getHRService: function(a){

gs.log("Script Include called ");
var hrservice = a;
var groups = [];
var gr1 = new GlideRecord('sn_hr_core_coe_security_policy');
gr1.addQuery('services',"CONTAINS",hrservice);
gr1.addOrCondition('type', 'write');
gr1.query();
if(gr1.next())
{
    var gr2 = new GlideRecord('sn_hr_core_m2m_security_policy_group');
    gr2.addQuery('security_policy',gr1.policy_name);
    gr2.query();
while(gr2.next()){
groups.push = gr2.group.sys_id;
}

}
return 'sys_idIN' +groups;

},
    type: 'HRAssignmentFilterUtil'
});

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@dvelloriy 

Few pointers

1) don't use gs.log(), use gs.info()

2) you are using wrong syntax to push value into array

3) you are comparing wrong value so I updated this line -> security_policy is reference so compare with sys_id

            gr2.addQuery('security_policy', gr1.sys_id);
 

4) ensure you are giving correct query -> is it AND or OR -> give it correctly here

        gr1.addOrCondition('type', 'write');
 

update as this

 

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

    getHRService: function(a) {

        gs.info("Script Include called ");
        var hrservice = a;
        var groups = [];
        var gr1 = new GlideRecord('sn_hr_core_coe_security_policy');
        gr1.addQuery('services', "CONTAINS", hrservice);
        // ensure you are giving correct query
        gr1.addOrCondition('type', 'write');
        gr1.query();
        if (gr1.next()) {
            var gr2 = new GlideRecord('sn_hr_core_m2m_security_policy_group');
            gr2.addQuery('security_policy', gr1.sys_id);
            gr2.query();
            while (gr2.next()) {
                groups.push(gr2.group.sys_id.toString());
            }
        }
        return 'sys_idIN' + groups.toString();
    },

    type: 'HRAssignmentFilterUtil'
});

 

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

6 REPLIES 6

Brad Bowman
Kilo Patron
Kilo Patron

Are you seeing the log to confirm this Script Include is running?  If, or once you are seeing this log, add another inside the if gr1 block and while gr2 block to confirm each is reached.  Once you get that far, you'll want to force the value pushed to the array to a string so that you don't get an array of the same value.  One way to do this is:

groups.push = gr2.group.toString();

You can also add a log before the return to check the value of the joined array:

gs.log('group array = ' + groups.join(',');
return 'sys_idIN' +groups.join(',');

Thanks Brad, this is now fixed.

There are few HR cases where HR service is empty. and there could be few scenarios where coe security rule might not be present. What is the recommended approach for such cases?

Do we show all HR groups as we don't want agents not able to assign cases to any assignment groups..and cases are lying in limbo..

Can you please advise here?