locked
Error message 'On Change': Cannot assign to a function result RRS feed

  • Question

  • Hi.

    In our CRM 2011 (RU16) implementation we have customized the CASE object.

    There is one script designed to calculate the number of days between case is raised and case is replied. The calculation works and th evalues are correct, however we get error messages and I would like to get rid of them.

    Attached the error messages and the related script.

    Can you please help me in spotting the bug?

    Many thanks

    function akzo_solveddate_onchange()
        {
            Xrm.Page.data.entity.attributes.get("new_datecompleted").fireOnChange();
            Xrm.Page.data.entity.attributes.get("akzo_dateclaimreceived").fireOnChange();
            if (Xrm.Page.getAttribute("akzo_solveddate").getValue() != null)
            {
               datebefore = Xrm.Page.getAttribute("akzo_solveddate").getValue();
               dateafter = datebefore.valueOf()+ (40*1000*3600*24);
               Xrm.Page.getAttribute("akzo_correctiveactiondue").setValue(dateafter);
            }
            else
            {
               Xrm.Page.getAttribute("akzo_correctiveactiondue").getValue() = null
            }
            Xrm.Page.data.entity.attributes.get("akzo_correctiveactiondue").setSubmitMode("always");

    Tuesday, August 26, 2014 3:48 PM

Answers

  • your function calls other two events, so we can't know for sure if the errors belong also to the other functions.

    you are setting the field akzo_correctiveactiondue 40 days after the date inside the field akzo_solveddate

    you need to use setValue and not getValue() = null to assign the value.

    try with this script

    function akzo_solveddate_onchange()
        {
            Xrm.Page.getAttribute("new_datecompleted").fireOnChange();
            Xrm.Page.getAttribute("akzo_dateclaimreceived").fireOnChange();
            if (Xrm.Page.getAttribute("akzo_solveddate").getValue() != null)
            {
               var datebefore = Xrm.Page.getAttribute("akzo_solveddate").getValue();
               var dateafter = new Date(datebefore.valueOf() + 40 * 24 * 3600 * 1000);
               Xrm.Page.getAttribute("akzo_correctiveactiondue").setValue(dateafter);
            }
            else
            {
               Xrm.Page.getAttribute("akzo_correctiveactiondue").setValue(null);
            }
            Xrm.Page.getAttribute("akzo_correctiveactiondue").setSubmitMode("always");
        }


    My blog: www.crmanswers.net - Rockstar 365 Profile


    Tuesday, August 26, 2014 4:29 PM

All replies

  • your function calls other two events, so we can't know for sure if the errors belong also to the other functions.

    you are setting the field akzo_correctiveactiondue 40 days after the date inside the field akzo_solveddate

    you need to use setValue and not getValue() = null to assign the value.

    try with this script

    function akzo_solveddate_onchange()
        {
            Xrm.Page.getAttribute("new_datecompleted").fireOnChange();
            Xrm.Page.getAttribute("akzo_dateclaimreceived").fireOnChange();
            if (Xrm.Page.getAttribute("akzo_solveddate").getValue() != null)
            {
               var datebefore = Xrm.Page.getAttribute("akzo_solveddate").getValue();
               var dateafter = new Date(datebefore.valueOf() + 40 * 24 * 3600 * 1000);
               Xrm.Page.getAttribute("akzo_correctiveactiondue").setValue(dateafter);
            }
            else
            {
               Xrm.Page.getAttribute("akzo_correctiveactiondue").setValue(null);
            }
            Xrm.Page.getAttribute("akzo_correctiveactiondue").setSubmitMode("always");
        }


    My blog: www.crmanswers.net - Rockstar 365 Profile


    Tuesday, August 26, 2014 4:29 PM
  • Many thanks. Unfortunately I got the scripts from a colleague that left the company, and I'm still learning...

    I tried the change you suggested, but it did not fix the problem. I have now a 'Object doesn't support property or method 'pagegetAttribute'.

    I attach the whole javascript (with the changes), not only the part I suspected...

    Many thanks indeed...

    function Form_onload()
    {

    function FilterCompanyLookup()
    {
        document.getElementById("customerid").setAttribute("lookuptypes", "1");
        document.getElementById("customerid").setAttribute("defaulttype", "1");
    }
    var uid = GetUserId();
    FilterCompanyLookup();
    var CRM_FORM_TYPE_CREATE = 1;
    var CRM_FORM_TYPE_UPDATE = 2;
    switch (Xrm.Page.ui.getFormType())
        {
            case CRM_FORM_TYPE_CREATE: //CREATE_FORM
                AutoPopulateUnit(uid);
            case CRM_FORM_TYPE_UPDATE: //UPDATE_FORM
                var oRealatedPicklist = Xrm.Page.getAttribute("akzo_complainprofile2");
                oRealatedPicklist.originalPicklistOptions = oRealatedPicklist.Options;
                if (Xrm.Page.getAttribute("akzo_complainprofile1").getValue() == null) {
                    oRealatedPicklist.setDisabled = true;
                }
                else
                {
                    var iPicklistValue = oRealatedPicklist.getValue();
                    crmForm.FilterPicklist();
                    oRealatedPicklist.setValue(iPicklistValue);
                }
                break;
        }
    }
    function Form_onsave()
        {
        var msg = 'Alert: specify whether the document refers to a customer, supplier or other.';
        var customerflag = Xrm.Page.data.entity.attributes.get("akzo_customerflag").getValue();
        var supplierflag = Xrm.Page.data.entity.attributes.get("akzo_supplierflag").getValue();
        var otherflag = Xrm.Page.data.entity.attributes.get("akzo_otherflag").getValue();
        
            if(customerflag=='' && supplierflag=='' && otherflag=='')
            {
         
                alert(msg);
                Xrm.Page.ui.controls.get("akzo_otherflag").setFocus();
         
                event.returnValue = false;    
            }
        }
    function akzo_complainprofile1_onchange()
        {
            crmForm.FilterPicklist();
        }

    function akzo_solveddate_onchange()
        {
            Xrm.Page.getAttribute("new_datecompleted").fireOnChange();
            Xrm.Page.getAttribute("akzo_dateclaimreceived").fireOnChange();
            if (Xrm.Page.getAttribute("akzo_solveddate").getValue() != null)
            {
               var dataprima = Xrm.Page.getAttribute("akzo_solveddate").getValue();
               var datadopo = new Date(dataprima.valueOf() + 40 * 24 * 3600 * 1000);
               Xrm.Page.getAttribute("akzo_correctiveactiondue").setValue(datadopo);
            }
            else
            {
               Xrm.Page.getAttribute("akzo_correctiveactiondue").setValue(null);
            }
            Xrm.PagegetAttribute("akzo_correctiveactiondue").setSubmitMode("always");
        }


    function akzo_dateclaimreceived_onchange()
        {
            if ((Xrm.Page.getAttribute("akzo_dateclaimreceived").getValue() != null) && (Xrm.Page.getAttribute("akzo_solveddate").getValue() != null))
            {
               Xrm.Page.getAttribute("akzo_fromcreatetoreply").setValue(((Xrm.Page.getAttribute("akzo_solveddate").getValue() - Xrm.Page.getAttribute("akzo_dateclaimreceived").getValue())/86400000));
            }
            else
            {
               Xrm.Page.getAttribute("akzo_fromcreatetoreply").setValue(null);
            }
            Xrm.Page.data.entity.attributes.get("akzo_fromcreatetoreply").setSubmitMode("always");
        }
    function akzo_situation_onchange()
        {
            Xrm.Page.getAttribute("akzo_situationchangedon").setValue(new Date());
            Xrm.Page.data.entity.attributes.get("akzo_situationchangedon").setSubmitMode("always");
        }
    function new_datecompleted_onchange()
        {
            if ((Xrm.Page.getAttribute("akzo_solveddate").getValue() != null) && (Xrm.Page.getAttribute("new_datecompleted").getValue() != null))
            {
               Xrm.Page.getAttribute("akzo_actionduecompleted").setValue(((Xrm.Page.getAttribute("new_datecompleted").getValue() - Xrm.Page.getAttribute("akzo_solveddate").getValue())/86400000));
            }
            else
            {
               Xrm.Page.getAttribute("akzo_actionduecompleted").getValue() = null
            }
            Xrm.Page.data.entity.attributes.get("akzo_actionduecompleted").setSubmitMode("always");
        }

    Tuesday, August 26, 2014 5:28 PM
  • I missed a dot in this line:

    Xrm.PagegetAttribute("akzo_correctiveactiondue").setSubmitMode("always");

    needs to be

    Xrm.Page.getAttribute("akzo_correctiveactiondue").setSubmitMode("always");
    try with this fix, however the code you posted contains several unsupported customizations.


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Tuesday, August 26, 2014 5:45 PM
  • <the code you posted contains several unsupported customizations>

    I'm pretty sure of it... our CRM 2011 is un upgrade from CRM 4.0...

    Tuesday, August 26, 2014 6:06 PM
  • OK, with the dot I only get one error.

    And thanks to your indications I found the remaining problem and fixed it... Another 'getValue() = Null' to change in 'setValue(null)

       Xrm.Page.getAttribute("akzo_actionduecompleted").getValue() = null

    Many thanks indeed!

    Wednesday, August 27, 2014 10:35 AM