Skip to Content
0
May 19, 2020 at 07:22 AM

UI5 function import with xmView

58 Views

Hello,

I am calling a function import to start a workflow in the backend. Currently I have implemented the logic in the controller.js as I need to perform different actions depending on the response. It is working fine, but is there a more elegant was to implement this function import call via the xml view?

I found a start here: Binding data from Odata function Import in SAPUI5 XML

but it does not cover the reaction to the response.

*********************** view.xml
<Button text="Start workflow" press="onStartWorkflow"/>

*********************** controller.js

onStartWorkflow : function () {
	var oModel = this.getView().getModel();
	oModel.callFunction(
		"/startWorkflow", {
			method: "GET",
			urlParameters: {
				task: "TSXXXXXX"
			},
			success: function (oData, response) {
				if (response.data.state === "Started") {
					MessageToast.show("Workflow" + response.wfID + "started");
				} else {
			MessageToast.show("workflow could not be started");
				}
			},
			error: function (oError) {
				MessageToast.show("oData call Error");
			}
		});
},