EDUCAÇÃO E TECNOLOGIA

A Fiori Journal : Collecting on all the Promises within Adaptations

Javascript uses the promises to execute asynchronous functions.

In another blog, I will discuss a way to raise a dialog box from a Fiori Elements List Adaptation. Here we look at using promises to collect results from asynchronous promises.

There’s a fairly recent keyword addition to Promises : Promises.allSettled(). This method allows us to collect on the resolution of all the identified promises and execute a collected then() branch only when all the promises are settled.

In this code snippet, I’m collecting all the executions of my function _executeTechnicallyComplete() into a table of references.

doCompleteAll: function( ) { for (var i = 0; i < selectedContext.length; i++) { var orderId = selectedContext[i].getProperty("MaintenanceOrder"); parameters.MaintenanceOrder = orderId; doTechnicalCompletions.push(this._executeTechnicallyComplete(parameters, i)); }

This snippet then invoke the executions using allSettled() and when executions are complete , the then() component refreshes my list report before closing my dialog.

Promise.allSettled(doTechnicalCompletions) .then(function () { this.getView().getModel().refresh(); this._techCompleteDialog.close(); }.bind(this)); }

Promises are handled asynchronously though.  One thing I noticed was that the dialog box was still active and multiple clicks on the buttons allow multiple executions.

One way to address it is to use the busy signal in extensionAPI.securedExecution .

I encapsulate my doCOmpleteAll in another function.

var fnTechnicallyComplete = function () { return new Promise(function (fnResolve, fnReject) { doCompleteAll( ).bind(this); }.bind(this)l this._oExtension.securedExecution(fnTechnicallyComplete, { busy: { set: true, check: true }, sActionLabel: "Technically Complete" }); 

This from a few streams of thought in Fiori that I have sitting on my One Note file.  They are not comprehensive references by any means, but some of them have been a product of collaboration with multiple sources. I wish to share them in the hopes some people would find them useful. If you notice anything which can be improved, please feel free to message me. All comments welcome.