【问题标题】:How Can I Query the Parent Record Using Javascript如何使用 Javascript 查询父记录
【发布时间】: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


    【解决方案1】:

    如果您正在为使用 Web API 检索数据的代码而苦恼,我建议您查看“CRM REST Builder”。

    https://github.com/jlattimer/CRMRESTBuilder

    导入解决方案并在动态中刷新解决方案页面,这将显示启动此工具的按钮。这个工具非常适合为不同的场景生成代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 2022-10-17
      • 2015-01-01
      • 2011-01-05
      相关资源
      最近更新 更多