Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
wilbert_sison2
Active Participant
0 Kudos
Javascript uses 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 invokes the executions using allSettled() and when executions are complete , the then()  branch 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.

Within Fiori Adaptations, one way to address it is to use the busy signal in in the Extension API : extensionAPI.securedExecution .

I encapsulate my doCompleteAll() in another function . This is then executed with a busy signal using securedExecution().
var fnTechnicallyComplete = function () {
return new Promise(function (fnResolve, fnReject) {
doCompleteAll( ).bind(this);
}.bind(this);
this._oExtension.securedExecution(fnTechnicallyComplete, {
busy: {
set: true,
check: true
},
sActionLabel: "Technically Complete"
});

 

 

 

I gather these 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. 
Labels in this area