
// Step 1: get task data
var startupParameters = this.getComponentData().startupParameters;
var taskModel = startupParameters.taskModel;
var taskData = taskModel.getData();
var taskId = taskData.InstanceID;
var processContext = new sap.ui.model.json.JSONModel();
$.ajax({
url: "/bpmworkflowruntime/rest/v1/task-instances/" + taskId + "/context",
method: "GET",
contentType: "application/json",
dataType: "json",
success: function(result, xhr, data) {
//Get the process context
processContext.context = data.responseJSON;
//Get task related data to be set in ObjectHeader
processContext.context.task = {};
processContext.context.task.Title = taskData.TaskTitle;
processContext.context.task.Priority = taskData.Priority;
processContext.context.task.Status = taskData.Status;
if (taskData.Priority === "HIGH") {
processContext.context.task.PriorityState = "Warning";
} else if (taskData.Priority === "VERY HIGH") {
processContext.context.task.PriorityState = "Error";
} else {
processContext.context.task.PriorityState = "Success";
}
processContext.context.task.CreatedOn = taskData.CreatedOn.toDateString();
}
});
//get task description and add it to the UI model
var jsonModel = new sap.ui.model.json.JSONModel();
startupParameters.inboxAPI.getDescription("NA", taskData.InstanceID).done(function(dataDescr) {
processContext.context.task.Description = dataDescr.Description;
jsonModel.setProperty("/context/task/Description", dataDescr.Description);
}).
fail(function(errorText) {
jQuery.sap.require("sap.m.MessageBox");
sap.m.MessageBox.error(errorText, {
title: "Error"
});
});
jsonModel.setData(processContext);
this.setModel(jsonModel);
//Implementation for the approve button action
var oPositiveAction = {
sBtnTxt: "Approve",
onBtnPressed: function(e) {
var model = that.getModel();
model.refresh(true);
//Call a local method to perform further action
that._triggerComplete(that.oComponentData.inboxHandle.attachmentHandle.detailModel.getData().InstanceID, true,
jQuery.proxy(
//on successful competion, call a local method to refresh the task list in My Inbox
that._refreshTask, that));
}
};
//Add 'Approve’ action to the task
startupParameters.inboxAPI.addAction({
action: oPositiveAction.sBtnTxt,
label: oPositiveAction.sBtnTxt,
type: "Accept"
//Set the onClick function
}, oPositiveAction.onBtnPressed);
//This method is called when the confirm button is click by the end user
_triggerComplete: function(taskId, approvalStatus, refreshTask) {
$.ajax({
//Call workflow API to get the xsrf token
url: "/bpmworkflowruntime/rest/v1/xsrf-token",
method: "GET",
headers: {
"X-CSRF-Token": "Fetch"
},
success: function(result, xhr, data) {
//After retrieving the xsrf token successfully
var token = data.getResponseHeader("X-CSRF-Token");
var dataText;
//form the context that will be updated - approval status and the equipment list
dataText = "{ \"status\":\"COMPLETED\",\"context\": {\"workplaceConfirmed\": \"" + approvalStatus + "\" }}";
$.ajax({
//Call workflow API to complete the task
url:"/bpmworkflowruntime/rest/v1/task-instances/"+taskId,
method: "PATCH",
contentType: "application/json",
//pass the updated context to the API
data: dataText,
headers: {
//pass the xsrf token retrieved earlier
"X-CSRF-Token": token
},
//refreshTask needs to be called on successful completion
success: refreshTask
});
}
});
},
//Request Inbox to refresh the control once the task is completed
_refreshTask: function() {
var taskId = this.getComponentData().startupParameters.taskModel.getData().InstanceID;
this.getComponentData().startupParameters.inboxAPI.updateTask("NA", taskId);
}
{
"user":{
"FirstName":"Kate",
"LastName":"Beckett",
"city":"London",
"country":"United Kingdom"
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
16 | |
14 | |
13 | |
11 | |
11 | |
11 | |
10 | |
8 | |
7 | |
6 |