Assign Change task based on the On-call schedule

koushik11
Tera Contributor

Hi - We have a ask from the users to assign the change task to their group and Assigned to he group member who is on-call at that moment.

 

Currently , there is already a task that get assigned to the group based on a check box on the change form. However, it is being assigned manually , we want to automate the process and assign to the user who is on-call from that specific group 

1 REPLY 1

Pankhil_UVA
Tera Contributor

var CreatePlannedTaskForOnCall = Class.create();
CreatePlannedTaskForOnCall.prototype = {
initialize: function() {},

createTaskForOnCall: function(groupSysId) {
var rota = new OnCallRotation();
rota.who(groupSysId);

var userName = rota.getPrimaryUserName();
var userID = rota.getPrimaryUser();

var task = new GlideRecord('planned_task'); // Modify the table name if needed
task.initialize();
task.short_description = 'Planned task for on-call person';
task.assigned_to = userID;
task.insert();

return task.sys_id;
},

type: 'CreatePlannedTaskForOnCall'
};

var groupSysId = ''; // Replace with actual group sys_id

var createPlannedTask = new CreatePlannedTaskForOnCall();
var taskSysId = createPlannedTask.createTaskForOnCall(groupSysId);

gs.info('Planned task created for on-call person. Task sys_id: ' + taskSysId);