locked
getdirty is Undefined. RRS feed

  • Question

  • I am trying to call the function below from OnSave but I keep getting: 

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

    Field:crmForm

    Event:onsave

    Error:Unable to get value of the property 'getIsDirty': object is null or undefined.

    and yes, I did check the box on the event to pass the context.

    function form_OnSave(context)
    {
        var zipDirty = Xrm.Page.getAttribute("address_postalcode").getIsDirty();
        var saveMode = context.getEventArgs().getSaveMode();
        alert(saveMode);
        if (zipDirty == true)
        {
            context.getEventArgs().preventDefault();
            //Xrm.Page.ui.controls.get("subject").setFocus();
            setTimeout(function () { Xrm.Page.data.entity.save(saveMode); }, 1000);
            
            //alert("Unable to save try saving again.");
            
              }
      
    }  

    Why is this and do you know any way of delaying the OnSave so my REST call completes?



    • Edited by PickyTech Monday, January 6, 2014 2:06 AM
    Saturday, January 4, 2014 9:49 PM

Answers

  • Hi,

    Seems like Xrm.Page.getAttribute("address_postalcode") is returning null in the first place. Can you validate if it is returning an object?


    Ronald

    • Proposed as answer by Guido PreiteMVP Saturday, January 4, 2014 11:02 PM
    • Marked as answer by PickyTech Wednesday, January 15, 2014 4:13 AM
    Saturday, January 4, 2014 10:51 PM

All replies

  • Hi,

    Seems like Xrm.Page.getAttribute("address_postalcode") is returning null in the first place. Can you validate if it is returning an object?


    Ronald

    • Proposed as answer by Guido PreiteMVP Saturday, January 4, 2014 11:02 PM
    • Marked as answer by PickyTech Wednesday, January 15, 2014 4:13 AM
    Saturday, January 4, 2014 10:51 PM
  • Hi Mark,

    Looks like Postal Code (address_postalcode) attribute is not placed inside the form. Try the below approach,

    var zipAttribute = Xrm.Page.getAttribute("address_postalcode");

    var isDirty = zipAttribute.getIsDirty();


    Prabhu G

    Sunday, January 5, 2014 8:28 AM
  • I think it should be address1_postalcode.

    So with a 1 (or a 2)

    • Marked as answer by PickyTech Monday, January 6, 2014 2:07 AM
    • Unmarked as answer by PickyTech Monday, January 6, 2014 2:09 AM
    Sunday, January 5, 2014 8:36 AM
  • Yes, that would be a fat finger mistake.  However, I still would like to know if anyone knows a good way of holding up a save so so that a web service request can finish.  I a trying to get address data from the web service, but if the user does not tab out of the zip field before hitting Save, it does not save the data that comes back from the web service.
    • Edited by PickyTech Monday, January 6, 2014 1:44 PM
    Monday, January 6, 2014 1:44 PM
  • Hi,

    Try using setSubmitMode after your web service updates those fields to force submitting those fields.


    Ronald

    Wednesday, January 8, 2014 6:59 PM