locked
onChange Undefined Error RRS feed

  • Question

  • Dear Gents,

    After i apply the Rollup 13 for MSCRM 2011 i start getting an error whenever i change any project status and thus the Project Status percentage is still the same.

    The Error says "There was as error with the Field's customized event"

    Event: onchange

    Error: Undefined.

    and Here is my code:

    function Form_onsave()

    {

    crmForm.all.new_process.ForceSubmit = true;

    }

    function new_pofsignoff_onchange()

    {

    if(document.crmForm.all.new_pofsignoff.DataValue ==1)

    { document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue+5;}

    else

    {document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue-5;}

    }

    function new_infraassesment_onchange()

    {

    if(document.crmForm.all.new_infraassesment.DataValue ==1)

    { document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue+5;}

    else

    {document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue-5;}

    }

    function new_projectplan_onchange()

    {

    if(document.crmForm.all.new_projectplan.DataValue ==1)

    { document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue+5;}

    else

    {document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue-5;}

    }

    function new_sitereadinessconfirmation_onchange()

    {

    if(document.crmForm.all.new_sitereadinessconfirmation.DataValue ==1)

    { document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue+5;}

    else

    {document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue-5;}

    }

    function new_implementation_onchange()

    {

    if(document.crmForm.all.new_implementation.DataValue ==1)

    { document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue+40;}

    else

    {document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue-40;}

    }

    function new_acceptancetest_onchange()

    {

    if(document.crmForm.all.new_acceptancetest.DataValue ==1)

    { document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue+10;}

    else

    {document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue-10;}

    }

    function new_documentationtraining_onchange()

    {

    if(document.crmForm.all.new_documentationtraining.DataValue ==1)

    { document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue+20;}

    else

    {document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue-20;}

    }

    function new_handoversignoff_onchange()

    {

    if(document.crmForm.all.new_handoversignoff.DataValue ==1)

    { document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue+10;}

    else

    {document.crmForm.all.new_process.DataValue=document.crmForm.all.new_process.DataValue-10;}

    }

    Can anyone Help me with this please.

    Best Regards...

    Ahmed.

    Monday, June 3, 2013 11:10 PM

Answers

  • you need to remove all the "document." prefix

    so needs to be as:

    Xrm.Page.getAttribute("new_process").getValue()


    instead of the wrong one

    document.Xrm.Page.getAttribute("new_process").getValue()

    EDIT: there are also logic errors to assign the value to the field, setValue must be used.

    try with this code:

    function Form_onsave()
    {
    	Xrm.Page.getAttribute("new_process").setSubmitMode("always");
    }
    
    function UpdateProcess(number) {
    	var newValue = Xrm.Page.getAttribute("new_process").getValue() + number;
    	Xrm.Page.getAttribute("new_process").setValue(newValue);
    }
    
    function new_pofsignoff_onchange()
    {
    	if (Xrm.Page.getAttribute("new_pofsignoff").getValue() == 1) { UpdateProcess(5); } else { UpdateProcess(-5); }
    }
    
    function new_infraassesment_onchange()
    {
    	if (Xrm.Page.getAttribute("new_infraassesment").getValue() == 1) { UpdateProcess(5); } else { UpdateProcess(-5); }
    }
    
    function new_projectplan_onchange()
    {
    	if (Xrm.Page.getAttribute("new_projectplan").getValue() == 1) { UpdateProcess(5); } else { UpdateProcess(-5); }
    }
    
    function new_sitereadinessconfirmation_onchange()
    {
    	if (Xrm.Page.getAttribute("new_sitereadinessconfirmation").getValue() == 1) { UpdateProcess(5); } else { UpdateProcess(-5); }
    }
    
    function new_implementation_onchange()
    {
    	if (Xrm.Page.getAttribute("new_implementation").getValue() == 1) { UpdateProcess(40); } else { UpdateProcess(-40); }
    }
    
    function new_acceptancetest_onchange()
    {
    	if (Xrm.Page.getAttribute("new_acceptancetest").getValue() == 1) { UpdateProcess(10); } else { UpdateProcess(-10); }
    }
    
    function new_documentationtraining_onchange()
    {
    	if (Xrm.Page.getAttribute("new_documentationtraining").getValue() == 1) { UpdateProcess(20); } else { UpdateProcess(-20); }
    }
    
    function new_handoversignoff_onchange()
    {
    	if (Xrm.Page.getAttribute("new_handoversignoff").getValue() == 1) { UpdateProcess(10); } else { UpdateProcess(-10); }
    }


    My blog: www.crmanswers.net






    Tuesday, June 4, 2013 10:28 AM

All replies

  • You are using the legacy CRM 4.0 object model for accessing fields. It may not be the direct cause of your issue, but it is strongly recommended that you rewrite code where possible to use the new CRM 2011 object model.

    For example:

    // CRM 4.0 syntax
    if (document.crmForm.all.new_pofsignoff.DataValue == 1)
    
    // In CRM 2011 syntax becomes:
    if (Xrm.Page.getAttribute('new_pofsignoff').getValue() == 1)

    There's a lot of information on MSDN about this, including -

    The CRM SDK reference on the CRM 2011 Xrm.Page object model: http://msdn.microsoft.com/en-us/library/gg334351.aspx

    Upgrade Your Code from Microsoft Dynamics CRM 4.0 to Microsoft Dynamics CRM 2011: http://msdn.microsoft.com/en-us/library/gg334220.aspx

    There are also various tools which can semi-automate the process for you, such as: https://crm2011scriptconvert.codeplex.com/

    Hope this helps.


    • Edited by Tully Нillenbrand Tuesday, June 4, 2013 12:50 AM Formatting hyperlinks
    • Proposed as answer by VidhiyaM Tuesday, June 4, 2013 4:59 AM
    Tuesday, June 4, 2013 12:49 AM
  • Hi,

    CRM 2011 doesn't support crmform as in 4.0. so use converter to convert your code from 4.0 to 2011

    https://crm2011scriptconvert.codeplex.com/



    VidhiyaM

    • Proposed as answer by VidhiyaM Tuesday, June 4, 2013 4:59 AM
    Tuesday, June 4, 2013 4:59 AM
  • Hi ,

    After the Roll up 12. They also had few changes in the Javascript also. As all the form design changed in the new rollups to Support the CRM for touch screen devices. they had updated the javascript library also to support the new changes.

    Please check the below link. it may give you some idea . http://dynamic-crm.com/javascript-in-crm-2011/


    With Regards Athul MT http://www.athulmt.blogspot.in/

    Tuesday, June 4, 2013 6:13 AM
  • Thank you for your replay.

    Actually, I have use the tool to convert the code and it convert it as the following:

    function Form_onsave()

    {

    Xrm.Page.getAttribute("new_process").setSubmitMode("always");

    }

    function new_pofsignoff_onchange()

    {

    if(document.Xrm.Page.getAttribute("new_pofsignoff").getValue() ==1)

    { document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()+5;}

    else

    {document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()-5;}

    }

    function new_infraassesment_onchange()

    {

    if(document.Xrm.Page.getAttribute("new_infraassesment").getValue() ==1)

    { document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()+5;}

    else

    {document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()-5;}

    }

    function new_projectplan_onchange()

    {

    if(document.Xrm.Page.getAttribute("new_projectplan").getValue() ==1)

    { document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()+5;}

    else

    {document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()-5;}

    }

    function new_sitereadinessconfirmation_onchange()

    {

    if(document.Xrm.Page.getAttribute("new_sitereadinessconfirmation").getValue() ==1)

    { document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()+5;}

    else

    {document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()-5;}

    }

    function new_implementation_onchange()

    {

    if(document.Xrm.Page.getAttribute("new_implementation").getValue() ==1)

    { document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()+40;}

    else

    {document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()-40;}

    }

    function new_acceptancetest_onchange()

    {

    if(document.Xrm.Page.getAttribute("new_acceptancetest").getValue() ==1)

    { document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()+10;}

    else

    {document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()-10;}

    }

    function new_documentationtraining_onchange()

    {

    if(document.Xrm.Page.getAttribute("new_documentationtraining").getValue() ==1)

    { document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()+20;}

    else

    {document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()-20;}

    }

    function new_handoversignoff_onchange()

    {

    if(document.Xrm.Page.getAttribute("new_handoversignoff").getValue() ==1)

    { document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()+10;}

    else

    {document.Xrm.Page.getAttribute("new_process").getValue()=document.Xrm.Page.getAttribute("new_process").getValue()-10;}

    }

    Unfortunately, I am still getting some errors.

    Please Advise what is the issue HERE.

    Regards,,,

    Tuesday, June 4, 2013 10:07 AM
  • you need to remove all the "document." prefix

    so needs to be as:

    Xrm.Page.getAttribute("new_process").getValue()


    instead of the wrong one

    document.Xrm.Page.getAttribute("new_process").getValue()

    EDIT: there are also logic errors to assign the value to the field, setValue must be used.

    try with this code:

    function Form_onsave()
    {
    	Xrm.Page.getAttribute("new_process").setSubmitMode("always");
    }
    
    function UpdateProcess(number) {
    	var newValue = Xrm.Page.getAttribute("new_process").getValue() + number;
    	Xrm.Page.getAttribute("new_process").setValue(newValue);
    }
    
    function new_pofsignoff_onchange()
    {
    	if (Xrm.Page.getAttribute("new_pofsignoff").getValue() == 1) { UpdateProcess(5); } else { UpdateProcess(-5); }
    }
    
    function new_infraassesment_onchange()
    {
    	if (Xrm.Page.getAttribute("new_infraassesment").getValue() == 1) { UpdateProcess(5); } else { UpdateProcess(-5); }
    }
    
    function new_projectplan_onchange()
    {
    	if (Xrm.Page.getAttribute("new_projectplan").getValue() == 1) { UpdateProcess(5); } else { UpdateProcess(-5); }
    }
    
    function new_sitereadinessconfirmation_onchange()
    {
    	if (Xrm.Page.getAttribute("new_sitereadinessconfirmation").getValue() == 1) { UpdateProcess(5); } else { UpdateProcess(-5); }
    }
    
    function new_implementation_onchange()
    {
    	if (Xrm.Page.getAttribute("new_implementation").getValue() == 1) { UpdateProcess(40); } else { UpdateProcess(-40); }
    }
    
    function new_acceptancetest_onchange()
    {
    	if (Xrm.Page.getAttribute("new_acceptancetest").getValue() == 1) { UpdateProcess(10); } else { UpdateProcess(-10); }
    }
    
    function new_documentationtraining_onchange()
    {
    	if (Xrm.Page.getAttribute("new_documentationtraining").getValue() == 1) { UpdateProcess(20); } else { UpdateProcess(-20); }
    }
    
    function new_handoversignoff_onchange()
    {
    	if (Xrm.Page.getAttribute("new_handoversignoff").getValue() == 1) { UpdateProcess(10); } else { UpdateProcess(-10); }
    }


    My blog: www.crmanswers.net






    Tuesday, June 4, 2013 10:28 AM
  • Dear Guido,

    Thank you for your kind help.

    Can you please explain more how can I use setValue since I don't have any experience with development staff and these codes has been done long time ago and now we are facing these issues.

    Please note that after removing "document." from all of the code there still some errors.

    Please Advise.

    Many Thanks...

    Tuesday, June 4, 2013 10:43 AM
  • amahrous, please try with the code I posted, as you can see now each function will test for the corresponding attribute(example: new_documentationtraining_onchange() with new_documentationtraining value) and after call a common function called UpdateProcess, inside the function the previous process value is modified and the result is set (using setValue method) to the field.


    My blog: www.crmanswers.net

    Tuesday, June 4, 2013 10:58 AM
  • Thank you so much Guido.

    Appreciate your kind help here.

    Regards,,

    Tuesday, June 4, 2013 11:36 AM