2 回答

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
在您的情況下,最好將 async/await 與fetch一起使用。
async function enableButton() {
const responseA = await fetch(accesstokenUrl, {
method: 'POST',
body: {
"access_token": "123"
},
});
const responseAJson = await responseA.json();
console.log("Response from the first fetch", responseAJson);
console.log("Your Access Token", responseAJson.access_token);
const responseB = await fetch(url, {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + responseAJson.access_token,
'Content-Type': 'application/json'
},
body: JSON.stringify(
{
"queryparams": true
})
});
console.log("Response from the second fetch", await responseB.json());
const hasDebtCase = getDebtCase(responseB.json());
if (hasDebtCase) {
return Promise.resolve(hasDebtCase);
} else {
return Promise.reject(data);
}
}

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超8個(gè)贊
請參閱下面的文章,了解在 Dynamics CRM 中使用啟用規(guī)則時(shí)如何返回承諾。 https://ajitpatra.com/2019/12/11/d365-enable-rule-for-button-with-asynchronous-api-request-using-promise/?utm_campaign=Dynamics%20Weekly&utm_medium=email&utm_source=Revue%20newsletter
如果我有幫助,請標(biāo)記我的答案已驗(yàn)證
添加回答
舉報(bào)