Need to cancel all task within the parent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 02:06 PM
Hello,
I Need to cancel all task within the parent.
I need to cancel the all child task when any child task is cancelled within a request.
So far when an end user cancels the parent, it cancels only the one child within the request. I need it to cancel all child task by stopping all potential tasks from being created. I also want to cancel all child task or any further task when an end user selects cancel from the portal or backend.
Below I have the UI actions and Portal Widget functions. They are working. However, they aren't fulfilling the full requirements listed above. Can someone help with my code?
Cancel button on task
Condition : (current.opened_by==gs.getUserID() || current.assigned_to==gs.getUserID()) && (current.state != 4)
var parentGr = new GlideRecord('x_g_duas_abm_contract_action_review');
parentGr.get(current.getValue('contract_action_review'));
parentGr.setValue('state', 107);
parentGr.update();
current.setValue("state", "4");
current.comments = "Request Cancelled by " + gs.getUserDisplayName();
current.update();
var flowGR = new GlideRecord('sys_flow_context');
flowGR.addQuery('source_record', parentGr.getValue('sys_id'));
flowGR.query();
flowGR.next();
sn_fd.FlowAPI.cancel(flowGR.getValue('sys_id'), 'Cancelled by submitter');
action.setRedirectURL(current);
Cancel Button on Parent
Condition : (current.opened_by==gs.getUserID() || current.assigned_to==gs.getUserID()) && (current.state != 107)
current.setValue("state", "107");
current.comments = "[code]<b>Request Cancelled</b>[/code] by " + gs.getUserDisplayName();
current.update();
var gr = new GlideRecord("x_g_duas_abm_contract_action_review_task");
gr.addQuery("contract_action_review", current.sys_id);
gr.query();
while (gr.next()) {
gr.setValue("state", "7");
gr.comments = "[code]<b>Request Cancelled</b>[/code] by " + gs.getUserDisplayName();
gr.update();
}
var flowGR = new GlideRecord('sys_flow_context');
flowGR.addQuery('source_record', current.sys_id);
flowGR.query();
flowGR.next();
sn_fd.FlowAPI.cancel(flowGR.getValue('sys_id'), 'Cancelled by submitter');
action.setRedirectURL(current);
Server Script
(function() {
data.pickupMsg = gs.getMessage(options.pickup_msg);
var gr = $sp.getRecord();
if (gr == null) return;
data.canRead = gr.canRead();
if (!data.canRead) return;
var agent = "";
var a = $sp.getField(gr, 'assigned_to');
if (a != null) agent = a.display_value;
var fields;
switch (gr.getTableName()) {
case 'x_g_duas_abm_unfunded_requirement':
fields = $sp.getFields(gr, 'number,state,mission_priority,sys_created_on');
fields[2].label = 'Priority';
break;
case 'x_g_duas_abm_abm_help_ticket':
fields = $sp.getFields(gr, 'number,state,sys_created_on');
data.helpTicket = true;
break;
default:
fields = $sp.getFields(gr, 'number,state,priority,sys_created_on');
}
if (gr.getValue("sys_mod_count") > 0) fields.push($sp.getField(gr, 'sys_updated_on'));
if (gr.getValue('price') > 0) fields.push($sp.getField(gr, 'price'));
if (gr.getValue('recurring_price') > 0) {
var rp = $sp.getField(gr, 'recurring_price');
if (gr.isValidField("recurring_price")) rp.display_value += " " + gr.getDisplayValue("recurring_frequency");
fields.push(rp);
}
if (gr.isValidField("quantity")) fields.push($sp.getField(gr, 'quantity'));
data.isMine = (gs.getUserID() == gr.getValue("opened_by")) || (gs.getUserID() == gr.getValue("assigned_to"));
data.tableLabel = gr.getLabel();
data.fields = fields;
data.variables = new global.GlobalServiceCatalogUtil().getVariablesForTask(gr, true);
data.agent = agent;
data.agentPossible = gr.isValidField("assigned_to");
data.assignedToMe = data.agentPossible && gr.getValue("assigned_to") == gs.getUserID();
data.table = gr.getTableName();
data.sys_class_name = gr.getValue("sys_class_name");
data.sys_id = gr.getUniqueValue();
data.state = gr.getValue('state');
data.more_info = gr.getValue('more_info');
data.variableSummarizerWidget = $sp.getWidget('sc-variable-summarizer', {
'variables': data.variables,
'toggle': true,
'task': fields[0].value
});
if (input) {
if (input.action == 'update_state') {
data.more_info = false;
gr.setValue('more_info', false);
gr.comments = "[code]<b>More Information Submitted</b> by [/code]" + gs.getUserDisplayName();
gr.update();
} else if (input.action == 'cancel') {
if (gr.getTableName() == 'x_g_duas_abm_contract_action_review_task') {
//cancel parent record
var parentGr = new GlideRecord('x_g_duas_abm_contract_action_review');
parentGr.get(gr.getValue('contract_action_review'));
parentGr.setValue('state', 107);
parentGr.update();
//cancel task record
gr.setValue('state', 4);
gr.comments = "Review task cancelled by " + gs.getUserDisplayName();
gr.update();
var flowGR = new GlideRecord('sys_flow_context');
flowGR.addQuery('source_record', parentGr.getValue('sys_id'));
flowGR.query();
if (flowGR.next()) sn_fd.FlowAPI.cancel(flowGR.getValue('sys_id'), 'Cancelled by submitter');
} else if (gr.getTableName() == 'x_g_duas_abm_contract_action_review') {
gr.comments = "Review cancelled by " + gs.getUserDisplayName();
gr.setValue('state', 107);
gr.update();
} else {
gr.setValue('state', 7);
gr.comments = "Request Cancelled by " + gs.getUserDisplayName();
gr.update();
}
var flowGR = new GlideRecord('sys_flow_context');
flowGR.addQuery('source_record', data.sys_id);
flowGR.query();
if (flowGR.next()) sn_fd.FlowAPI.cancel(flowGR.getValue('sys_id'), 'Cancelled by submitter');
} else if (input.action == 'complete') {
gr.setValue('state', gr.getTableName() == 'x_g_duas_abm_srrb' ? -17 : 3);
gr.comments = "Review task completed by " + gs.getUserDisplayName();
gr.update();
}
}
})();
Client Controller
api.controller = function($scope, $rootScope, spUtil) {
var c = this;
spUtil.recordWatch($scope, $scope.data.table, "sys_id=" + $scope.data.sys_id);
var isUserModified = function() {
return false;
};
$rootScope.$on('spModel.gForm.rendered', function(e, gFormInstance) {
if (gFormInstance.getTableName().indexOf("x_g_duas_abm") > -1) {
isUserModified = gFormInstance.isUserModified;
$scope.disableResubmit = isUserModified();
}
});
c.action = function() {
$rootScope.$broadcast("action.initiated");
c.server.get({
action: 'update_state'
}).then(function() {});
};
c.cancelAction = function() {
$rootScope.$broadcast("action.initiated");
c.server.get({
action: 'cancel'
}).then(function() {});
};
c.completeAction = function() {
$rootScope.$broadcast("action.initiated");
c.server.get({
action: 'complete'
}).then(function() {});
};
c.showContractActionReviewOptions = function() {
return c.data.table === 'x_g_duas_abm_contract_action_review_task' && c.data.assignedToMe;
};
c.showSRRBOptions = function() {
return c.data.table === 'x_g_duas_abm_srrb';
};
$scope.disableResubmit = false;
$rootScope.$on("field.change", function(e, parms) {
if (parms.field.name !== "comments" && parms.field.name !== "work_notes") {
$scope.disableResubmit = isUserModified();
}
});
$rootScope.$on("sp.form.record.updated", function() {
$scope.disableResubmit = false;
});
};
Any help would be great. Thank you.