奇怪的错误TypeError:无法在onSuccessMapUnitFields上读取null的属性"setValue" [英] weird Error TypeError: Cannot read property 'setValue' of null at onSuccessMapUnitFields

查看:88
本文介绍了奇怪的错误TypeError:无法在onSuccessMapUnitFields上读取null的属性"setValue"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码运行良好,直到我决定再添加4行代码,所以我删除了它们.但是我遇到了这个错误,有趣的是我在 Form_onload 函数上添加了我的代码行.我需要这方面的帮助.

This code was running fine until I decided to add 4 more lines of code, so I removed them. But I got this error, funny thing is I added my lines on the Form_onload function. I need help with this.

function Form_OnLoad() {
    debugger;
        if (Xrm.Page.ui.getFormType() == 1) {
            Xrm.Page.getAttribute("quantity").setValue(1);
            Xrm.Page.getAttribute("quantity").setSubmitMode("always");
            Xrm.Page.getAttribute("isproductoverridden").setValue(true);

  Xrm.Page.getAttribute("isproductoverridden").setSubmitMode("always");
        }
        else {
            ActOnFields("disable", "ir_unit");
            ActOnFields("show", "salesorderid");
        }
    }

    function Unit_OnChange() {
        var Unit = Xrm.Page.getAttribute("ir_unit").getValue();
        if (Unit != null && Unit.length > 0) {
            var lookupid = Unit[0].id;
            var oDataSetName = "ir_unitSet";
            var columns = "ir_AmountRate,ir_Expenses,ir_PublishedRate";
            var filter = "ir_unitId eq (guid'" + lookupid + "')";
            retrieveMultiple(oDataSetName, columns, filter, "", onSuccessMapUnitFields);
            Xrm.Page.getAttribute("productdescription").setValue(Unit[0].name);
            Xrm.Page.getAttribute("productdescription").setSubmitMode("always");
        }
        else {
            Xrm.Page.getAttribute("priceperunit").setValue(null);
            Xrm.Page.getAttribute("priceperunit").setSubmitMode("always");
            Xrm.Page.getAttribute("baseamount").setValue(null);
            Xrm.Page.getAttribute("baseamount").setSubmitMode("always");
        }
    }
    function onSuccessMapUnitFields(data, textStatus, XmlHttpRequest) {
        if (data && data.length > 0) {
            var price = 0;
            //if (data[0].ir_AmountRate != null && data[0].ir_AmountRate.Value != null) {
            //price += parseFloat(eval(data[0].ir_AmountRate.Value));
            //}
            if (data[0].ir_PublishedRate != null) {
                price += parseFloat(eval(data[0].ir_PublishedRate));
            }
            if (data[0].ir_Expenses != null && data[0].ir_Expenses.Value != null) {
                price += parseFloat(eval(data[0].ir_Expenses.Value));
            }
            Xrm.Page.getAttribute("priceperunit").setValue(price);
            Xrm.Page.getAttribute("priceperunit").setSubmitMode("always");
            Xrm.Page.getAttribute("baseamount").setValue(price);
            Xrm.Page.getAttribute("baseamount").setSubmitMode("always");
            Xrm.Page.getAttribute("ir_publishedrate").setValue(price);
            Xrm.Page.getAttribute("ir_publishedrate").setSubmitMode("always");
        }
    }

推荐答案

Unit_OnChange 函数&中添加 debugger; 成功回调函数 onSuccessMapUnitFields ,然后在调试时可以找出 priceperunit baseamount ir_publishedrate中3个字段中的哪一个引发此错误.

Add debugger; inside Unit_OnChange function & the success callback function onSuccessMapUnitFields, then while debugging you can figure out that which one of the 3 fields among priceperunit, baseamount, ir_publishedrate is throwing this error.

在调用此 setValue(price)之前,还要验证是否正在调用 ActOnFields 方法以将这3个字段隐藏在其他位置.因为如果控件/属性以以下形式不可见- Xrm.Page.getAttribute 返回 null ,那么当您尝试对 setValue 进行操作时失败,并显示此错误.

Also verify if you are calling ActOnFields method to hide those 3 fields anywhere else before calling this setValue(price). Because if the control/attribute is not visible in the form - Xrm.Page.getAttribute returns null, then when you are trying to setValue it fails with this error.

故障保护方法:

if(Xrm.Page.getAttribute("baseamount") != null){
       Xrm.Page.getAttribute("baseamount").setValue(price);
       Xrm.Page.getAttribute("baseamount").setSubmitMode("always");
}

这篇关于奇怪的错误TypeError:无法在onSuccessMapUnitFields上读取null的属性"setValue"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆