Skip to Content

App crashes upon deployment on the backend system (!!!)

Hello experts,

I have an app that is working just fine with SAP Web IDE (personal edition). I deployed the application in my back-end system and, when I started testing and to my big surprise, after I tried to save an erroneous entry (wanted to see if error messages are coming as expected), I got the error "Cannot read property 'getParent' of undefined". "Undefined" refers to a message popover that I use in my base controller. Exception doesn't occur within my code but within MessagePopover-dbg.js (snapshot attached below, line in error 1209).

SAPUI5 version on Web IDE: 1.44.12

SAPUI5 version on back-end system: 1.44.23

Base controller code, along with the routine that calls the popover attached below. Under other circumstances, I would normally issue a note to SAP but, since I'm new in SAPUI5, I'm not 100% sure that I'm not missing anything. Any ideas?

/********** Base controller ***********/


sap.ui.define([
		"sap/ui/core/mvc/Controller",
		"sap/ui/model/json/JSONModel",
		"sap/m/MessagePopover",
		"sap/m/MessagePopoverItem"
	], function (Controller, JSONModel, MessagePopover, MessagePopoverItem) {
		"use strict";


		var oMessageTemplate = new MessagePopoverItem({
			type: "{type}",
			title: "{title}",
			description: "{description}"
		});	
		var oMessagePopover = new MessagePopover({
			id: "actionEditMessagePopover", 
			items: {
				path: '/',
				template: oMessageTemplate
			}
		});	


		var msgModel = new JSONModel("testModel");
				
		return Controller.extend("kristal.apps.agreements.controller.BaseController", {
			/**
			 * Convenience method for accessing the router.
			 * @public
			 * @returns {sap.ui.core.routing.Router} the router for this component
			 */
			getRouter : function () {
				return sap.ui.core.UIComponent.getRouterFor(this);
			},


			/**
			 * Convenience method for getting the view model by name.
			 * @public
			 * @param {string} [sName] the model name
			 * @returns {sap.ui.model.Model} the model instance
			 */
			getModel : function (sName) {
				return this.getView().getModel(sName);
			},


			/**
			 * Convenience method for setting the view model.
			 * @public
			 * @param {sap.ui.model.Model} oModel the model instance
			 * @param {string} sName the model name
			 * @returns {sap.ui.mvc.View} the view instance
			 */
			setModel : function (oModel, sName) {
				return this.getView().setModel(oModel, sName);
			},


			/**
			 * Getter for the resource bundle.
			 * @public
			 * @returns {sap.ui.model.resource.ResourceModel} the resourceModel of the component
			 */
			getResourceBundle : function () {
				return this.getOwnerComponent().getModel("i18n").getResourceBundle();
			},


			/**
			 * Event handler when the share by E-Mail button has been clicked
			 * @public
			 */
			onShareEmailPress : function () {
				var oViewModel = (this.getModel("objectView") || this.getModel("worklistView"));
				sap.m.URLHelper.triggerEmail(
					null,
					oViewModel.getProperty("/shareSendEmailSubject"),
					oViewModel.getProperty("/shareSendEmailMessage")
				);
			},
			_renderSAPMessages: function(response, sStart, oControl) {
				// Extract messages
				// Catch logic works when we have multiple lines, re-initializes
				// next line proccessing
				this.messageArray = [];
				var message;
				var start = sStart + 14;
				var resultString = response.substring(start);
				var messageStart = resultString.indexOf("code") - 1;
				var messageEnd = resultString.indexOf("details") - 2;
				while (messageEnd > 0) {
					message = "{" + resultString.substring(messageStart, messageEnd) + "}";
					message = message.replace("severity\":", "type\": ");
					//message = message.replace("message\":", "description\": ");
					message = message.replace("message\":", "subtitle\": ");
					message = message.replace("code\":", "title\": ");
					message = message.replace("error", "Error");	
					message = message.replace("warning", "Warning");
					message = message.replace("Z666Z", "\",\"description\": \"");
					try {
						message = JSON.parse(message);
						message.title = message.title + " " + message.subtitle;
						this.messageArray.push(message);
						var streamEnd = resultString.indexOf("}]}") - 1;
						messageEnd += 1;
						if (streamEnd < messageEnd) {
						//	messageEnd = 0;
							start = resultString.indexOf("sap-message: {") + 14;
							if (start > 0) {
								resultString = resultString.substring(start);
								messageStart = resultString.indexOf("code") - 1;
								messageEnd = resultString.indexOf("details") - 2;
							} else {
								messageEnd = 0;
							}						
						} else {
							resultString = resultString.substring(messageEnd);
							messageStart = resultString.indexOf("code") - 1;
							if (messageStart > 0) {
								messageEnd = resultString.indexOf("}");
							}
							else {
								break;
							}
						}
					}
					catch(err) {
						start = resultString.indexOf("sap-message: {") + 14;
						if (start > 0) {
							resultString = resultString.substring(start);
							messageStart = resultString.indexOf("code") - 1;
							messageEnd = resultString.indexOf("details") - 2;
						} else {
							messageEnd = 0;
						}
					}					
				}
	
				msgModel.setData(this.messageArray);
	
				oMessagePopover.setModel(msgModel);			
	
				if (this.messageArray.length > 0) {
					oMessagePopover.openBy(oControl);
				}
			},
			_checkIfBatchRequestSucceeded: function(oEvent) {
				var oParams = oEvent.getParameters();
				var aRequests = oEvent.getParameters().requests;
				var oRequest;
				if (oEvent.getParameters().response.responseText.indexOf("sap-message: {") !== null) {
					return true;	
				}
				else
				{
					if (oParams.success) {
						if (aRequests) {
							for (var i = 0; i < aRequests.length; i++) {
								oRequest = oEvent.getParameters().requests[i];
								if (!oRequest.success) {
									return false;
								}
							}
						}
						return true;
					} else {
						return false;
					}
				}
			},
			_checkMessagePopoverState: function() {
				if (oMessagePopover.isOpen()) {
					oMessagePopover.close();
				}
			}
		});


	}
);

/*********************** call to Popover ************************/


			onHeaderSave: function() {


				var that = this;
				var oModelUpdateDeferred = jQuery.Deferred();
				var bCheckSuccess;
				var oModel = this.getView().getModel();


				this._checkMessagePopoverState();
				// abort if the  model has not been changed
				if (!oModel.hasPendingChanges()) {
					MessageBox.information(
						this.getResourceBundle().getText("noChangesMessage"), {
							id: "noChangesInfoMessageBox",
							styleClass: that.getOwnerComponent().getContentDensityClass()
						}
					);
					return;
				}			


				oModel.attachEventOnce("batchRequestCompleted", function(oEvent) {
				// Get control to display message list next to 
				var oControl = sap.ui.getCore().byId("application-agreements-display-component---object--objectAgreementHeaderForm");
					if (that._checkIfBatchRequestSucceeded(oEvent)) {
						that._renderSAPMessages(oEvent.getParameters().response.responseText,
						oEvent.getParameters().response.responseText.indexOf("sap-message: {"),
						oControl);
						if (oEvent.getParameters().response.responseText.indexOf("sap-message: {") < 0) {
							bCheckSuccess = true;	
						} else {
							bCheckSuccess = false;	
						}	
 						oModelUpdateDeferred.resolve();	
					}
				});
					
				oModel.submitChanges({
					success: function(oData, sResponse) {
					},
					error: function(oError) {
						jQuery.sap.log.error("oData Failure", oError);
					}
				});	
				var readyToGo = function() {
					if (bCheckSuccess === true) {
						this.getView().byId("saveHeaderButton").setVisible(false);
						this.getView().byId("cancelHeaderButton").setVisible(false);
						this.getView().byId("editHeaderButton").setVisible(true);
						this._bindHeaderReadOnly();
					}
				};
				jQuery.when(oModelUpdateDeferred).done().then( jQuery.proxy(readyToGo, this) );				
			}

popover-error.jpg (316.1 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    May 18 at 05:18 PM

    It was not the popover, problem was the declaration of the control responsible for the popover position on the screen. It was declared using sap.ui.getCore() and the full qualified path of the control, something really unwise, since it's generated dynamically on runtime and on a different environment is subject to change...

    Add comment
    10|10000 characters needed characters exceeded