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
如果我有帮助,请标记我的答案已验证
添加回答
举报