Show assignment groups for particular HR Service
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 11:36 AM - edited 12-20-2023 11:43 AM
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:gs.getUser().getMyGroups();
ref qualifier on HR Case: javascript: 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;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 11:51 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 12:07 PM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 12:13 PM
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'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 12:26 PM - edited 12-20-2023 12:27 PM
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.
Is it possible to get sys_ids without array?