Search code examples
odatasapui5formatter

Can I use oData calls within a formatter?


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) ); 
        }

Solution

  • Workaround is creating the association in SEGW and using the expand function, no formatter here