Business Applications, dynamics 365, Dynamics 365 - new UI, PowerApps

How do I pass executionContext as a parameter into my Promise to fit in Promise.all()?

To be honest, this post should be a bit longer with more details but I like it this way.

This is a sample below. It looks cool. And I building one of my own. But I need it to work with my onSave form validation.

const promise1 = Promise.resolve(3);
const promise2 = 42;
const promise3 = new Promise((resolve, reject) => {
  setTimeout(resolve, 100, 'foo');

Promise.all([promise1, promise2, promise3]).then((values) => {

I am making two Web API calls to query data to enforce some business rules. They have to be wrapped into Promise.all as per docs:

I don’t normally use OnSave validation but unfortunately it’s required for my scenario.

I need to pass executionContext parameter into my Promise. And I do it like this:

const validateRateCard = context => {
        return new Promise(function (resolve, reject) {
            var formContext = context.getFormContext();

            var field = formContext.getAttribute("field_name").getValue();           
            var url = "<your_query_here>";
            Xrm.WebApi.retrieveMultipleRecords("<your_table_here", url).then(
                function success(result) {
                    // return true or false
                    if (result.entities.length > 0) {
                        resolve("NOT SO GOOD!");
                    else {
                        resolve("AWESOME COOKIES!");
                function (error) {

The cool stuff that you could find the info on how to pass a parameter by Googling it. And the answer will always be “wrap your Promise into a function, pass the parameter into the function”.

It wasn’t clear still how to call that function and how to pass all this “celebration” all together into Promise.all the way it looks appropriate.

Promise.all([validateRateCard(executionContext), promise2]).then((values) => {
            for (const element of values) {
//lets iterate through the results

The absolute MUST reading if you play with OnSave validation is the article from Andrew Butenko:

Good luck! You need it.

1 thought on “How do I pass executionContext as a parameter into my Promise to fit in Promise.all()?”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s