Show assignment groups for particular HR Service

miro2
Mega Sage

Hi
I'm looking for an option to combine both reference qualifiers into one OR add logic from the first reference qualifier to the script include.

For HR Case and a specific HR Service, I want to choose only assignment groups where the user is a member. When the particular HR Service is used on a case, the user should only be able to choose groups of which they are a member (here I don't what to use escalation script). In other cases, the escalation script from the script include should run.

I tried to return the caseSysid when hr_service is <sys_id of a particular HR service>, but it didn't work.

 

ref qualifier 1: sys_idINjavascript&colon;gs.getUser().getMyGroups();

ref qualifier on HR Case: javascript&colon; new HRCaseUtils().escalations(current.sys_id);

 

script include:

 

	escalations: function(caseSysid) {
		var query = 'sys_idIN';
		
		var hrCase = new GlideRecord('sn_hr_core_case');
		hrCase.get(caseSysid);

		var groups = new GlideRecord('sn_hr_core_escalations');
		groups.addQuery('u_matcher', hrCase.assignment_group);
		groups.query();
		while(groups.next()) {
			query += groups.u_setter + ',';
		}
		return query;
	},

 

 

7 REPLIES 7

Aniket Chavan
Tera Sage
Tera Sage

Hello @miro2 ,

 

Please try with the script below and let me know how it works for you.

Script Include:

var HRCaseUtils = Class.create();
HRCaseUtils.prototype = {

    getAssignmentGroups: function(caseSysid) {
        var hrCase = new GlideRecord('sn_hr_core_case');
        hrCase.get(caseSysid);

        var userGroups = gs.getUser().getMyGroups();
        var assignmentGroups = [];

        // Check if the HR Service matches the specific HR Service you are targeting
        if (hrCase.hr_service == '<sys_id_of_your_specific_HR_Service>') {
            var groups = new GlideRecord('sn_hr_core_escalations');
            groups.addQuery('u_matcher', hrCase.assignment_group);
            groups.query();
            while (groups.next()) {
                assignmentGroups.push(groups.u_setter);
            }
        } else {
            // Include logic for other cases or use the escalation script from your original implementation
            assignmentGroups = this.escalations(caseSysid);
        }

        return 'sys_idIN' + assignmentGroups.join(',');
    },

    escalations: function(caseSysid) {
        var query = [];

        var hrCase = new GlideRecord('sn_hr_core_case');
        hrCase.get(caseSysid);

        var groups = new GlideRecord('sn_hr_core_escalations');
        groups.addQuery('u_matcher', hrCase.assignment_group);
        groups.query();
        while(groups.next()) {
            query.push(groups.u_setter);
        }

        return query;
    },

    type: 'HRCaseUtils'
};

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Regards,

 

Aniket

@Aniket Chavan thanks for you reply
it doesn't work. I'm not sure if you understood my requirement so I will explain it here.

When HR Service on HR case is my particular HR service then I want to run gs.getUser().getMyGroups() or similar logic to fetch groups that user is member of. And I don't see variable userGroups used in script.

Hello @miro2 ,

 

Sorry for the confusion 😅

Please see the below modified script once and let me know your feedback since I have not tested it from my end.

var HRCaseUtils = Class.create();
HRCaseUtils.prototype = {

    getAssignmentGroups: function(caseSysid) {
        var hrCase = new GlideRecord('sn_hr_core_case');
        if (hrCase.get(caseSysid)) {
            var userGroups = gs.getUser().getMyGroups();
            
            // Check if the HR Service matches the specific HR Service you are targeting
            if (hrCase.hr_service == '<sys_id_of_your_specific_HR_Service>') {
                return 'sys_idIN' + userGroups.join(',');
            } else {
                return this.escalations(caseSysid);
            }
        }
        return '';
    },

    escalations: function(caseSysid) {
        var query = [];

        var hrCase = new GlideRecord('sn_hr_core_case');
        if (hrCase.get(caseSysid)) {
            var groups = new GlideRecord('sn_hr_core_escalations');
            groups.addQuery('u_matcher', hrCase.assignment_group);
            groups.query();
            while(groups.next()) {
                query.push(groups.u_setter);
            }
        }

        return 'sys_idIN' + query.join(',');
    },

    type: 'HRCaseUtils'
};

still doesn't work

When I checked in background script below script:

 

var userGroups = gs.getUser().getMyGroups();
gs.print('sys_idIN' + userGroups.join(','));

 


I got 

sys_idINundefined

 
but when I removed join(',')

 

 var userGroups = gs.getUser().getMyGroups();
gs.print('sys_idIN' + userGroups);

 


I received sys_ids in array.
miro2_0-1703103837217.png
Is it possible to get sys_ids without array?