1

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");
        }
    }

1 Answer 1

1

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.

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.

Failsafe approach:

if(Xrm.Page.getAttribute("baseamount") != null){
       Xrm.Page.getAttribute("baseamount").setValue(price);
       Xrm.Page.getAttribute("baseamount").setSubmitMode("always");
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.