cancel
Showing results for 
Search instead for 
Did you mean: 

set expanded oData model from workflow instance

0 Kudos

Hello,

I want to show some expanded data from workflow instance in MyInbox. The coding is in the init function in Component.js.

Expanding Data showing as standalone works.

init: function () {
	UIComponent.prototype.init.apply(this, arguments);

	var that = this;

	this.getModel("oData").read("/TravelAndExpenseHeaders('001118130000059123_____')", {
		urlParameters: {
			"$expand": "Claims,Destinations,CostAssignments,Attachments"
		},
		success: function (myData) {
			var model = new sap.ui.model.json.JSONModel(myData);
			that.setModel(model);
		}
	});

	// enable routing
	this.getRouter().initialize();

	// set the device model
	this.setModel(models.createDeviceModel(), "device");
}

Showing not expanded data from workflow instance in MyInbox also works.

init: function () {
	// call the base component's init function
	UIComponent.prototype.init.apply(this, arguments);

	// get workflow-instance
	var that = this;
	var startupParameters = this.getComponentData().startupParameters;
	var taskModel = startupParameters.taskModel;
	var taskData = taskModel.getData();
	var taskId = taskData.InstanceID;

	// set 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 action Approve
	startupParameters.inboxAPI.addAction({
		action: "Approve",
		label: "Genehmigen",
		type: "Accept"
	}, function (button) {
		this._approveObject(taskId, true);
	}, this);

	// add action Reject
	startupParameters.inboxAPI.addAction({
		action: "Reject",
		label: "Ablehnen",
		type: "Reject"
	}, function (button) {
		this._approveObject(taskId, false);
	}, this);

	// enable routing
	this.getRouter().initialize();

	// set the device model
	this.setModel(models.createDeviceModel(), "device");
}

But the combination does not work.

init: function () {
	// call the base component's init function
	UIComponent.prototype.init.apply(this, arguments);

	// get workflow-instance
	var that = this;
	var startupParameters = this.getComponentData().startupParameters;
	var taskModel = startupParameters.taskModel;
	var taskData = taskModel.getData();
	var taskId = taskData.InstanceID;

	// set model
	var contextModel = new sap.ui.model.json.JSONModel("/bpmworkflowruntime/rest/v1/task-instances/" + taskId + "/context").attachRequestCompleted(

		// read TravelAndExpenseHeaderID
		function (data) {
			var travelAndExpenseHeaderID = this.getProperty("/TravelAndExpenseHeaderID");
			var name = "/TravelAndExpenseHeaders('" + travelAndExpenseHeaderID + "')";
				
			// expanded model
			that.getModel("oData").read(name, {
				urlParameters: {
					"$expand": "Claims,Destinations,CostAssignments,Attachments"
				},
				success: function (myData) {
					var model = new sap.ui.model.json.JSONModel(myData);
					that.setModel(model);
				}
			});

		});

	contextModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay);

	//add action Approve
	startupParameters.inboxAPI.addAction({
		action: "Approve",
		label: "Genehmigen",
		type: "Accept"
	}, function (button) {
		this._approveObject(taskId, true);
	}, this);

	// add action Reject
	startupParameters.inboxAPI.addAction({
		action: "Reject",
		label: "Ablehnen",
		type: "Reject"
	}, function (button) {
		this._approveObject(taskId, false);
	}, this);

	// enable routing
	this.getRouter().initialize();

	// set the device model
	this.setModel(models.createDeviceModel(), "device");
}

Can anyone help me? Where is my error?

Domi
Contributor
0 Kudos

Hi

are there any errors?

Where does the combined code break?

regards

Domi

Accepted Solutions (0)

Answers (0)