【发布时间】:2021-09-01 11:07:54
【问题描述】:
Click here for picture Overview of the classes/entities
大家好,如果有人可以重新编码并帮助我,那就太好了。我是 D365 和 JS 的新手。基本上,如何使用JS从调整发票记录中查询父级到case_adjustment。我已经提供了我当前的代码,请帮我检查一下。我已经尝试了一切,但到目前为止还没有运气。对不起我不专业的照片。但我希望你能理解并帮助我针对这种情况编写代码。
我尝试启用调试器,它显示代码无法运行adjustmentTypeLookup。这就是它无法将值传递给 retrieveRecord 的原因。谢谢。
function adjustmentInvoiceApproveAmount(executionContext) {
try {
// Get the form context
const formContext = executionContext.getFormContext();
// Extract attribute values from the form
const adjustmentAmount = formContext.getAttribute("case_adjustmentamount").getValue();
const amountDue = formContext.getAttribute("case_amountdue").getValue();
const adjustmentTypeLookup = formContext.getAttribute("case_adjustmenttype").getValue();
// Exit as adjustmenttype is not set
if (!adjustmentTypeLookup) return;
// Extract the adjustment type record ID from the payment type lookup
const adjustmentTypeId = adjustmentTypeLookup[0].id.substring(1, 37);
//console.log("GUID \"case_adjustmenttype\" = " + adjustmentTypeId + " ; " + typeof adjustmentTypeId);
//console.log(adjustmentTypeId);
// Retrieve a SINGLE case_adjustmenttype based on lookup ID on form
Xrm.WebApi.retrieveRecord("case_adjustmenttype", adjustmentTypeId, "$select=case_name").then(
function success(adjustmentType)
{
// If the payment type is credit notes then check payment amount and resit amount
if (adjustmentType.case_name.toLowerCase() == "Credit notes".toLowerCase())
{
if (adjustmentAmount >= amountDue) {
formContext.getEventArgs().preventDefault();
Xrm.Navigation.openErrorDialog({message:"Payment Amount cannot be more than Resit Amount."})
}
}
//Otherwise do nothing
},
function (error)
{
console.log(error.message);
}
);
}
catch (error)
{
console.log(error);
}
}
【问题讨论】:
标签: javascript dynamics-crm office365api