Cireson Portal - Resolution Description Required
Dear All,
I have the following code to set the resolution to be required in the custom.js posted here. However when enabling parent incident functionality and trying to resolve a parent incident it doesn't work. Clicking on the "OK" button doesn't allow a parent incident to be closed. Any help with this would be really appreciated.
Kind Regards
Daniel
+++++ Code +++++
// Adding required to resolution description
app.custom.formTasks.add('Incident', null, function (formObj, viewModel) {
formObj.boundReady(function () {
var changewindow = $($.find("#ChangeStatusWindow"));
var changewindowWrapper = changewindow.find(".cireson-window--wrapper");
var changewindowFooter = changewindowWrapper.find(".cireson-window--footer");
var changewindowFooterErrorDiv = changewindowWrapper.find("#changeStatusErrorWin");
var okButton = changewindowFooter.find(".btn-primary");
//hide original ok button
okButton.hide();
//close dialog
hideWindow = function () {
$(".k-window").hide();
$(".k-overlay").hide();
}
//custom ok button click event
customOkButtonClick = function () {
var workItemStatuses = app.constants.workItemStatuses;
//map all the status constants to shorter local vars. used in getFormTaskViewModel() and getFormTaskChangeRules()
var incidentResolved = workItemStatuses.Incident.Resolved;
var incidentActive = workItemStatuses.Incident.Active;
var incidentClosed = workItemStatuses.Incident.Closed;
var serviceRequestCompleted = workItemStatuses.ServiceRequest.Completed;
var serviceRequestClosed = workItemStatuses.ServiceRequest.Closed;
var problemResolved = workItemStatuses.Problem.Resolved;
var problemClosed = workItemStatuses.Problem.Closed;
var requireResolution = false;
if (pageForm.viewModel.Status.Id == incidentResolved) {
requireResolution = true;
}
var actionLogType = app.controls.getWorkItemLogType(viewModel);
if (_.isString(viewModel.Status.Name) && viewModel.Status.Name.length < 1) {
viewModel.set("Status", { Id: originalVm.Status.Id, Name: originalVm.Status.Name });
} else if (requireResolution && (!_.isUndefined(viewModel.ResolutionCategory) && _.isNull(viewModel.ResolutionCategory.Id))) {
//changewindowFooter.find('#changeStatusErrorWin').html(localization.RequestCategoryRequiredError);
kendo.ui.ExtAlertDialog.show({
title: localization.Warning,
message: localization.RequestCategoryRequiredError
});
} else if (requireResolution && _.isNull(viewModel.Notes) && (vm.type == "ServiceRequest")) {
//changewindowFooter.find('#changeStatusErrorWin').html(localization.ImplementationNotesRequiredError);
kendo.ui.ExtAlertDialog.show({
title: localization.Warning,
message: localization.ImplementationNotesRequiredError
});
} else if (requireResolution && (!_.isUndefined(viewModel.ResolutionDescription) && _.isNull(viewModel.ResolutionDescription))) {
//modalWindowEle.find('#changeStatusErrorWin').html("Resolution Description is a required field");
kendo.ui.ExtAlertDialog.show({
title: localization.Warning,
message: "Please enter a Resolution Description"
});
}
else if (viewModel.Status.Id === incidentResolved) { //resolved incident
//set resolved date
viewModel.set("ResolvedDate", new Date().toISOString());
var resDateEle = $("input[name='ResolvedDate']");
if (resDateEle.attr('data-control') == 'datePicker') {
resDateEle.val(kendo.toString(new Date(), "d"));
} else if (resDateEle.attr('data-control') == 'dateTimePicker') {
resDateEle.val(kendo.toString(new Date(), "g"));
}
//add to action log
if (actionLogType) {
viewModel[actionLogType].unshift(new app.dataModels["AppliesToTroubleTicket"].recordResolved(viewModel.ResolutionDescription));
}
//set resolved by user
viewModel.RelatesToTroubleTicket = { BaseId: session.user.Id };
//if incident is a parent, check if we need to resolve its child incidents
if (viewModel.IsParent && (this.resolveChildSettings.ResolveChildIncident || (this.resolveChildSettings.ResolvedLetAnalystDecide && this.resolveChildIncident)))
resolveChildIncidents(this.resolveChildSettings);
changewindowFooter.find('#changeStatusErrorWin').html("");
hideWindow();
} else if (viewModel.Status.Id === incidentClosed || viewModel.Status.Id === serviceRequestClosed || viewModel.Status.Id === problemClosed) { //closed IR or closed SR
//set closed date
viewModel.set("ClosedDate", new Date().toISOString());
var closeDateEle = $("input[name='ClosedDate']");
if (closeDateEle.attr('data-control') == 'datePicker') {
closeDateEle.val(kendo.toString(new Date(), "d"));
} else if (closeDateEle.attr('data-control') == 'dateTimePicker') {
closeDateEle.val(kendo.toString(new Date(), "g"));
}
//set closed by user
switch (viewModel.Status.Id) {
case problemClosed:
viewModel.RelatesToTroubleTicket_ = { BaseId: session.user.Id };
break;
case incidentClosed:
viewModel.RelatesToTroubleTicket_ = { BaseId: session.user.Id };
viewModel[actionLogType].unshift(new app.dataModels["AppliesToTroubleTicket"].recordClosed());
break;
case serviceRequestClosed:
viewModel.ClosedByUser = { BaseId: session.user.Id };
break;
}
changewindowFooter.find('#changeStatusErrorWin').html("");
hideWindow();
}
else if (viewModel.Status.Id === incidentActive) { //activate incident
viewModel.RelatesToTroubleTicket = { BaseId: null };
viewModel.ResolutionCategory.set("Id", null);
viewModel.ResolutionCategory.set("Name", "");
viewModel.set("ResolutionDescription", null);
viewModel.set("ResolvedDate", null);
//add to action log
var actionLogType = app.controls.getWorkItemLogType(viewModel);
if (actionLogType) {
viewModel[actionLogType].unshift(new app.dataModels["AppliesToTroubleTicket"].recordActivated());
}
changewindowFooter.find('#changeStatusErrorWin').html("");
hideWindow();
} else if (viewModel.Status.Id === serviceRequestCompleted) { //completed service request
//set completed date
viewModel.set("CompletedDate", new Date().toISOString());
var comDateEle = $("input[name='CompletedDate']");
if (comDateEle.attr('data-control') == 'datePicker') {
comDateEle.val(kendo.toString(new Date(), "d"));
} else if (comDateEle.attr('data-control') == 'dateTimePicker') {
comDateEle.val(kendo.toString(new Date(), "g"));
}
changewindowFooter.find('#changeStatusErrorWin').html("");
hideWindow();
} else if (viewModel.Status.Id === problemResolved) { //resolved problem
//set resolve date
viewModel.set("ResolvedDate", new Date().toISOString());
var comDateEle = $("input[name='ResolvedDate']");
if (comDateEle.attr('data-control') == 'datePicker') {
comDateEle.val(kendo.toString(new Date(), "d"));
} else if (comDateEle.attr('data-control') == 'dateTimePicker') {
comDateEle.val(kendo.toString(new Date(), "g"));
}
//set resolved by user
viewModel.RelatesToTroubleTicket = { BaseId: session.user.Id };
if (viewModel.IsAutoResolve) {
resolveRelatedWorkItems();
}
viewModel.set("AutoResolve", viewModel.IsAutoResolve);
changewindowFooter.find('#changeStatusErrorWin').html("");
hideWindow();
} else {
changewindowFooter.find('#changeStatusErrorWin').html("");
hideWindow();
}
}
//add the new custom button to form
var customOkButton = $("<button id='customOKButton' onClick=customOkButtonClick() data-role='button' class='btn btn-primary'>Ok</button>");
changewindowFooterErrorDiv.after(customOkButton);
});
});
Answers
@CaterhamITSupport - Have you tried the Resolve Incident Addin?
User Guide: Add-In - Resolve IR Task (cireson.com)