2 回答

TA貢獻1859條經驗 獲得超6個贊
在您的情況下,最好將 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貢獻1785條經驗 獲得超8個贊
請參閱下面的文章,了解在 Dynamics CRM 中使用啟用規則時如何返回承諾。 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
如果我有幫助,請標記我的答案已驗證
添加回答
舉報