none
Error :object doesn't support the property or method

    Question

  • Dear all;

    on form load i am doing some calculation the calculation works fi9 if i don't use this line of code 

    if(Xrm.Page.data.entity.getIsDirty()==true){



    Xrm.Page.data.entity.save();
    }

    but when i use the above line of code i am getting the following error

    There was an error with this field's customized event.

    Field:window

    Event:onload

    Error: 'object doesn't support the property or method. 

    please help

    Wednesday, February 08, 2012 3:45 PM

All replies

  • It seems rather odd to do a save right away in an onload script.  Perhaps the Xrm.Page.data.entity object has not been fully initialized at the time you're making the call.  Debugging your javascript should reveal the current state of the object when your code is running, and if your getIsDirty() and save() functions have been initialized at that time.
    Friday, February 10, 2012 4:01 PM
  • Hi Anwar,

    I've had this issue this week, after updating to RU6. I have some values that I need to change and immediatly save on the OnLoad event and I was having the same javascript error.

    After some debuging there was a error when the CRM javascript disables all the form controls right before the saving. When it tries to get the Sub-Grids controls they return null and the Xrm.Page.data.entity.save() method throws an exception. 

    After contacting support this appears to be a bug, the workarround is to add the Sub-Grids to a new tab (or use the current, that's up to you) and in the tab properties uncheck the "Expand this tab by default" so the tab shows up as Collapsed by default. This should solve the error.

    If you really need to keep the tab expanded (like I did), I imagine you're doing something like:

    if(something) 
    {
     (..).setValue(val);
     (..).save();
    }

    just add

    else 
    {
     Xrm.Page.ui.tabs.get(“<tab name>”).setDisplayState(“expanded”);
    }
    to keep the tab appear as always expanded.

    Let me know if this helped.


    Regards, João

    • Proposed as answer by Ken Allgood Monday, April 30, 2012 1:10 PM
    Friday, February 10, 2012 6:21 PM
  • Do you write some javacript for OnSave event, if so, could it work without exception?


    daemon lin

    Friday, February 10, 2012 7:08 PM
  • Hi All,

    I have the same issue. Any news about this ?

    Max

    Thursday, March 08, 2012 10:16 AM
  • Thanks for this info, I couldn't find it anywhere!  We're working on upgrading to CRM 2011, and I have UR6 set up on my test box, and I came across the same issue.  I need to recalculate some fields during the onload and possibly have it call onsave() during the load.  I moved the sub-grids to their own tab and collapse them for the onload process.  It's not critical for us to have the sections expanded, so I didn't worry about putting the javascript in to do that.
    Monday, April 30, 2012 1:10 PM
  • Had the same issue and the solution of João worked fine.

    Best regards,
    Philip

    Tuesday, July 09, 2013 3:11 PM