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

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

Awesome, thanks Ankur. Its working now. 

One issue. 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 dont agents not able to assign cases to any assignment groups..and cases are lying in limbo..

Please advise..

@dvelloriy 

Glad to know that my script worked.

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

@dvelloriy 

Best to discuss with customer. In this case you can show all groups.

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