Skip to Content
0
Former Member
Nov 15, 2017 at 10:21 AM

SAPUI5 APP for Workflow Error -- - Cannot read property ‘startupParameters’ of undefined

2022 Views

I made a SAPUI5 APP for inserting to the workflow according to this artical:

How to build a simple approval UI

When I build the APP, there was an error facing:

Uncaught TypeError: Cannot read property 'startupParameters' of undefined

In the project, the wrong code that caused the error is in the Component.js:

var startupParameters = this.getComponentData().startupParameters;

in Debug, this.getComponentData() is undifined, it doesn't get a return value.

Does anybody know how could I solve the issue?

Here is the whole code:

Component.js

sap.ui.define([
	"sap/ui/core/UIComponent",
	"sap/ui/Device",
	"LaunchWorkflow/model/models"
], function(UIComponent, Device, models) {
	"use strict";


	return UIComponent.extend("LaunchWorkflow.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();
			
			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);			
			//add actions
			startupParameters.inboxAPI.addAction({
				action: "Approve",
				label: "Approve"
			}, function(button){
				this._completeTask(taskId, true);
			}, this);
			startupParameters.inboxAPI.addAction({
				action: "Reject",
				label: "Reject"
			}, function(button){
				this._completeTask(taskId, false);
			}, this);
		},
		_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
				}
			});
			this._refreshTask(taskId);
		},
		_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;
		},
		_refreshTask: function(taskId) {
			this.getComponentData().startupParameters.inboxAPI.updateTask("NA", taskId);
		}
	});
});

here is the image the APP after launching:

Attachments

approve-reject.jpg (118.4 kB)