salesdocapprovalreason = 'ZEXT'.
salesdocapprovalreason = 'ZEXT'.
* Exit added as Workflow triggered via via EMS. Just left sentimental purpose
Exit.
* Check if the outbound service is available
CHECK cl_ble_http_client=>is_service_available(
communication_scenario = 'YY1_OAUTH_TOKEN'
outbound_service = 'YY1_OAUTH_REST'
) = abap_true.
* Create HTTP client to access the outbound service
DATA(lo_client0) = cl_ble_http_client=>create(
communication_scenario = 'YY1_OAUTH_TOKEN'
outbound_service = 'YY1_OAUTH_REST'
).
CHECK cl_ble_http_client=>is_service_available(
communication_scenario = 'YY1_WORKFLOW'
outbound_service = 'YY1_WORKFLOW_REST'
) = abap_true.
* Create HTTP client to access the outbound service
DATA(lo_client) = cl_ble_http_client=>create(
communication_scenario = 'YY1_WORKFLOW'
outbound_service = 'YY1_WORKFLOW_REST'
).
DATA lv_request_body TYPE string.
Data lv_temp TYPE String.
lv_temp = salesdocument-totalnetamount.
CONCATENATE '{"definitionId": "workflowSO", "context": {"SONr": "' salesdocument-SALESDOCUMENT '","netval": "' lv_temp '","creator": "' salesdocument-createdbyuser '" }}' INTO lv_request_body.
* First we have to get the bearer token before we can make the actual request
DATA(request0) = cl_ble_http_request=>create( )->set_method( if_ble_http_request=>co_method-post )->set_body( lv_request_body ).
TRY.
DATA(response0) = lo_client0->send( request0 ).
DATA(lv_body1) = response0->get_body( ).
SPLIT lv_body1 AT '":"' INTO DATA(LV_NADA) DATA(LV_TAIL).
SPLIT LV_TAIL AT '","' INTO DATA(lv_bearer) DATA(LV_MORE_NADA).
CONCATENATE 'Bearer' lv_bearer INTO lv_bearer SEPARATED BY space.
* Creation of the service request
DATA(request) = cl_ble_http_request=>create(
* method that is used for the service call
)->set_method(
if_ble_http_request=>co_method-post
)->set_body( lv_request_body
)->set_header_parameter(
EXPORTING
name = 'Content-Type'
value = 'application/json'
)->set_header_parameter(
EXPORTING
name = 'Authorization'
value = lv_bearer
)->set_header_parameter(
EXPORTING
name = 'Accept'
value = '*/*'
).
* Send a request and receive a response.
DATA(response) = lo_client->send( request ).
* Get the body of the response.
DATA(lv_body) = response->get_body( ).
/*eslint no-console: 0*/
"use strict";
var http = require("http");
var request = require("request");
var port = process.env.PORT || 3000;
http.createServer(function (req, res) {
if (req.method === 'OPTIONS') {
//This is the branch taking care of the initial handshake
console.log('OPTIONS request coming through…');
var headers = {};
headers["WebHook-Allowed-Origin"] = "*";
res.writeHead(200, headers);
res.end();
} else {
//EMS queue entry branch.. .
res.writeHead(200, {
"Content-Type": "text/plain"
});
let body = [];
//rudimentary way to get the body of the EMS Webhook call containing the SO ID
req.on('data', (chunk) => {
body.push(chunk);
}).on('end', () => {
body = Buffer.concat(body).toString();
console.log(body);
//Getting more SO data, EMS only provides ID
var auth = "Basic " + new Buffer('ZPH' + ":" + 'XXXX').toString("base64");
var SONr = JSON.parse(body).data.KEY[0].SALESORDER;
request({
url: "https://my300187-api.s4hana.ondemand.com/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder('" + SONr +
"')?$format=json&saml2=disabled",
headers: {
"Authorization": auth
}
},
function (error, response, body2) {
console.log(body2);
var value = JSON.parse(body2).d.TotalNetAmount;
var created = JSON.parse(body2).d.CreatedByUser;
//Compile JSON to trigger Workflow
var wfdata = {
"definitionId": "workflowSO",
"context": {
"SONr": SONr,
"netval": value,
"creator": created
}
};
var auth2 = "Basic " + new Buffer('fd5cf1c8-5e1a-361d-b74c-1d08aaff5207' + ":" + 'XXXXXXX').toString("base64");
//REST call to get assess token
request({
method: 'POST',
url: "https://oauthasservices-i123456trial.hanatrial.ondemand.com:443/oauth2/api/v1/token?grant_type=client_credentials",
form: JSON.stringify(wfdata),
headers: {
"Authorization": auth2
}
},
function (error, response, body3) {
console.log(body3);
var token = JSON.parse(body3).access_token;
//REST call to trigger Workflow
request({
method: 'POST',
url: "https://bpmworkflowruntimewfs-i123456trial.hanatrial.ondemand.com:443/workflow-service/rest/v1/workflow-instances",
headers: {
"Authorization": "Bearer " + token,
"Content-Type": "application/json"
},
json: wfdata
},
function (error, response, body3) {
console.log(body3);
}
);
}
);
}
);
});
res.end("OK\n");
}
}).listen(port);
console.log("Server listening on port %d", port);
//Based on the creator we define the approvers for level 1 and level 2
var approvers = [{
"creator": "CB9980002292",
"approver": ["I123456", "I123456"]
}];
//If we don’t have a configuration for an approver we use the default
var defaultapprover = ["I123456", "I123456"];
var result = null;
for (var i=0; i<approvers.length;i++)
{
if (approvers[i].creator = $.context.creator) {result = approvers[i].approver;}
}
if (result == null ) { result = defaultapprover;}
$.context.approverarr = result;
$.context.nextapprover = result[0];
<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" controllerName="pkg1.WorkflowApp2.controller.View1" displayBlock="true">
<Shell id="shell">
<App id="app">
<pages>
<Page id="page" title="Debit Request Approval">
<content>
<sap.ui.layout.form:SimpleForm xmlns:sap.ui.layout.form="sap.ui.layout.form" xmlns:sap.ui.core="sap.ui.core" editable="true" layout="ResponsiveGridLayout" id="form0">
<sap.ui.layout.form:content>
<sap.ui.core:Title text="Please Approve the creation of the following DR" id="title0"/>
<Label text="Net Value:" id="label0"/>
<Input width="100%" id="input0" value="{/netval}"/>
<Label text="Creator:" id="label1"/>
<Input width="100%" id="input2" value="{/creator}"/></sap.ui.layout.form:content>
</sap.ui.layout.form:SimpleForm>
</content>
</Page>
</pages>
</App>
</Shell>
</mvc:View>
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/Device",
"XXX/WorkflowApp2/model/models"
], function (UIComponent, Device, models) {
"use strict";
return UIComponent.extend("XXX.WorkflowApp2.Component", {
metadata: {
manifest: "json"
},
/**
* The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
* @public
* @override
*/
init: function () {
// call the base component's init function
UIComponent.prototype.init.apply(this, arguments);
// enable routing
this.getRouter().initialize();
// set the device model
this.setModel(models.createDeviceModel(), "device");
// get task data
var startupParameters = this.getComponentData().startupParameters;
var taskModel = startupParameters.taskModel;
var taskData = taskModel.getData();
var taskId = taskData.InstanceID;
// initialize model
var contextModel = new sap.ui.model.json.JSONModel("/bpmworkflowruntime/rest/v1/task-instances/" + taskId + "/context");
contextModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay);
this.setModel(contextModel);
startupParameters.inboxAPI.addAction({
action: "REJECT",
label: "Reject"
}, function(button) {
this._completeTask(taskId, false);
}, this);
startupParameters.inboxAPI.addAction({
action: "APPROVE",
label: "Approve"
}, function(button) {
this._completeTask(taskId, true);
}, this);
},
_fetchToken: function() {
var token;
$.ajax({
url: "/bpmworkflowruntime/rest/v1/xsrf-token",
method: "GET",
async: false,
headers: {
"X-CSRF-Token": "Fetch"
},
success: function(result, xhr, data) {
token = data.getResponseHeader("X-CSRF-Token");
}
});
return token;
},
_completeTask: function(taskId, approvalStatus) {
var token = this._fetchToken();
$.ajax({
url: "/bpmworkflowruntime/rest/v1/task-instances/" + taskId,
method: "PATCH",
contentType: "application/json",
async: false,
data: "{\"status\": \"COMPLETED\", \"context\": {\"approved\":" + approvalStatus + "}}",
headers: {
"X-CSRF-Token": token
}
});
if (approvalStatus === true) {sap.m.MessageToast.show("Task Approved!");} else {sap.m.MessageToast.show("Task Rejected!");}
this._refreshTask(taskId);
},
_refreshTask: function(taskId) {
this.getComponentData().startupParameters.inboxAPI.updateTask("NA",taskId);
}
});
});
if ($.context.netval <1000)
{
$.context.nextapprover = ""}
else
{
$.context.approverarr.shift();
$.context.nextapprover = $.context.approverarr[0];
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
10 | |
7 | |
7 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 |