Skip to Content

Can I use oData calls within a formatter?

Hello experts,

I have implemented a function import which accepts a partner code from entity A and returns the partner description from entity B. Cannot use associations here, since code is not part of the entity A key and SEGW doesn't allow me to create one. Loading data from entity B at the beginning not an option either, contains more than 150.000 entries. Function import works just fine, my problem is that the formatter doesn't seem to wait for the data coming back from the oData call, even though I have attached both a promise and the "batchrequestcompleted" event. I watched all the instructions executed in the correct order inside the debugger (and returning the expected result) but seems like the view doesn't wait. Is there some kind of technique I can use to make theview wait for the result or do I have to attach extra fields in my entity A in order to store the description in the backend, something that for obvious reasons I don't want to do. (Really short) code attached below, any ideas?

Cheers,

Greg

PS: someone will easily notice when observing the code that the value is returned twice, once in the success function and once after the promise. It's simply for testing, after all, none of them works :D

			textPartner : function (sValue) {
				if (!sValue) {
					return "";
				}
				var that = this.getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent().getController();
				var oModel = this.getModel();
				var oModelUpdateDeferred = jQuery.Deferred();


				oModel.attachEventOnce("batchRequestCompleted", function(oEvent) {
					if (that._checkIfBatchRequestSucceeded(oEvent)) {
 						oModelUpdateDeferred.resolve();	
					}
				});
				
				oModel.callFunction("/Get_Partner_Name", { urlParameters: { Partner_Code: sValue },
					success: function(oData, sResponse) {
						sValue = oData.ReturnValue;
						return sValue;
					},
					error: function(oError) {
						jQuery.sap.log.error("oData Failure", oError);
					}
				});	
				var readyToGo = function() {
					return sValue;
				};
				jQuery.when(oModelUpdateDeferred).done().then( jQuery.proxy(readyToGo, this) );	
			}

        /* 2nd simplified synchronous version, behaves the same way */

        textPartner : function (sValue) {
				if (!sValue) {
					return "";
				}
				var oModel = this.getModel();


				oModel.callFunction("/Get_Partner_Name", { urlParameters: { Partner_Code: sValue }, async: false,
					success: function(oData, sResponse) {
						sValue = oData.ReturnValue;
						//return sValue;
					},
					error: function(oError) {
						jQuery.sap.log.error("oData Failure", oError);
					}
				});
				return sValue;
			}
        

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    May 25, 2018 at 02:20 PM

    Workaround is following Jun Wu approach (suggestion 1) with SEGW (ignore the key thing) and get the data using expand in the binding. Synchronous logic doesn't seem to work.

    Add comment
    10|10000 characters needed characters exceeded

  • May 24, 2018 at 12:04 PM

    1. If I am not worng, association should work, key won't matter

    2. make your odata call synchronus

    Add comment
    10|10000 characters needed characters exceeded

  • May 25, 2018 at 09:03 AM

    Hi,

    The association should works like Jun Wu said. But when you do your association, you have to do it with a different logic.

    Please look at this blog

    https://blogs.sap.com/2017/12/21/list-report-adding-a-contact-quick-view-to-a-table-without-cds/

    at the section

    SAP Gateway part : Data Model it will show you how to create an association with that logic.

    Kind Regards,

    Joseph

    Add comment
    10|10000 characters needed characters exceeded

    • I already have the association part working, tested and working fine in SEGW, my problem now is with the binding, check my last answer in the thread, thanks for stepping in to help anyway :-)