Help on configuration step for assignment group
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2024 09:31 AM
Hello
I have this catalog item where you can complaint about the closed incident ticket. I'm trying to build an automated test on this. Each of the incidents came from various of departments. I have the configuration steps where you can pick individual group for tasks or approvers. How would you build the configuration step for the group that based on the assigned incident ticket. For example if the closed ticket came from "PC support group", I want the ticket automatically assigns to that group for catalog task. Here is my current configuration step:
Description generation script:
(function generateDescription(step) {
var description = 'Return random fulfiller(s) as follows:' + '\n';
description += "Fulfiller 1 from group '" + step.inputs.u_group_one.getDisplayValue();
description += "' (Change Approver = " + step.inputs.u_change_approver_one.getDisplayValue() + ")\n";
if(step.inputs.u_group_two) {
description += "Fulfiller 2 from group '" + step.inputs.u_group_two.getDisplayValue();
description += "' (Change Approver = " + step.inputs.u_change_approver_two.getDisplayValue() + ")";
}
return description;
})(step);
Step execution script:
(function executeStep(inputs, outputs, stepResult, timeout) {
//===== USER 1 =====
var user1Arr = [];
// Locate users
var user1Gr = new GlideRecord('sys_user_grmember');
user1Gr.addEncodedQuery('user.active=true^user.roles=itil^group=' + inputs.u_group_one);
if(inputs.u_change_approver_one == 'yes') {
user1Gr.addQuery('u_change_approver', true);
}
if(inputs.u_change_approver_one == 'no') {
user1Gr.addQuery('u_change_approver', false);
}
user1Gr.query();
while (user1Gr.next()) {
user1Arr.push(user1Gr.user.toString());
}
// Locate random user
var user1Random = Math.floor((Math.random() * user1Arr.length));
outputs.u_fulfiller_one = user1Arr[user1Random];
//===== USER 2 =====
if(global.JSUtil.notNil(inputs.u_group_two)) {
var user2Arr = [];
// Locate users
var user2Gr = new GlideRecord('sys_user_grmember');
user2Gr.addEncodedQuery('user.active=true^user.roles=itil^group=' + inputs.u_group_two);
if(inputs.u_change_approver_two == 'yes') {
user2Gr.addQuery('u_change_approver', true);
}
if(inputs.u_change_approver_two == 'no') {
user2Gr.addQuery('u_change_approver', false);
}
user2Gr.query();
// Do not add the same user
while (user2Gr.next()) {
if(user1Arr.indexOf(user2Gr.user.toString() == -1)) {
user2Arr.push(user2Gr.user.toString());
}
}
// Locate random user
var user2Random = Math.floor((Math.random() * user2Arr.length));
outputs.u_fulfiller_two = user2Arr[user2Random];
}
//===== STEP RESULT =====
var msg = '';
if(global.JSUtil.notNil(outputs.u_fulfiller_one)) {
var returnUser1Gr = new GlideRecord('sys_user_grmember');
returnUser1Gr.addEncodedQuery('group=' + inputs.u_group_one + '^user=' + outputs.u_fulfiller_one);
returnUser1Gr.query();
if(returnUser1Gr.next()) {
msg += 'Located fulfiller 1: ' + returnUser1Gr.user.name + ' with id ' + returnUser1Gr.user.user_name + ' in group ';
msg += returnUser1Gr.group.getDisplayValue() + ' (Change Approver = ' + returnUser1Gr.u_change_approver + ')\n';
}
if(global.JSUtil.notNil(outputs.u_fulfiller_two)) {
var returnUser2Gr = new GlideRecord('sys_user_grmember');
returnUser2Gr.addEncodedQuery('group=' + inputs.u_group_two + '^user=' + outputs.u_fulfiller_two);
returnUser2Gr.query();
if(returnUser2Gr.next()) {
msg += 'Located fulfiller 2: ' + returnUser2Gr.user.name + ' with id ' + returnUser2Gr.user.user_name + ' in group ';
msg += returnUser2Gr.group.getDisplayValue() + ' (Change Approver = ' + returnUser2Gr.u_change_approver + ')\n';
}
}
stepResult.setOutputMessage(msg);
stepResult.setSuccess();
} else {
stepResult.setOutputMessage('Failed to locate fulfillers');
stepResult.setFailed();
}
}(inputs, outputs, stepResult, timeout));
Input Variables:
Output Variables
0 REPLIES 0