Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Return promise in enable rule

(0) ShareShare
ReportReport
Posted on by 60

I have written code using fetch to return a Promise to Dynamics in an Enable Rule, but I am not receiving the correct data in return to Dynamics.

If I test with a simple function like this in Dynamics it works:

function enableButton() { 
    return new Promise(function (resolve, reject) {
                var test = true; 
                resolve(test); 
            }, 
            function (error) { 
                reject(error.message); 
                console.log(error.message); 
            } 
        ); 
    }

If I do it like this it does not return the promise correct:


function enableButton() { 
    fetch(accesstokenUrl, {
        method: 'POST',
        body: 
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
        .then(function (response) {
            return response.json();
        })
        .then(function (resJson) {
            return fetch(url, {
                method: 'POST',
                headers: {
                    'Authorization': 'Bearer '   resJson.access_token,
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(
                    {
                        "queryparams": true
                    })
            });
        })
        .then(function (res) {
            return res.json();
        })
        .then(function (data) {
         const hasDebtCase = getDebtCase(data);
              if (hasDebtCase) {
                return Promise.resolve(hasDebtCase);
            } else {
                return Promise.reject(data);
            }  
        })
        .catch((error) => {
            console.error('Error:', error);
        })
};

What is the problem with this?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans