locked
Error on calling the Xrm.Page.entity.save() method in the form onLoad event RRS feed

  • Question

  • Hi all,

    here is a simple code that I don't understand why it doesn't work.

    --------

    function onLoad_account() {
        Xrm.Page.data.entity.attributes.get("fax").setValue("12345678");
        Xrm.Page.data.entity.save();
     }

    -------

    As you can see, in the OnLoad event I simply set the value of fax = "12345678" and then I save the record but the system give me the error "Object doesn't suport the property or method". Perhaps isn't possible save in the onload event?

    Could you help me?

    Thanks :)

    Monday, June 24, 2013 4:22 PM

All replies

  • The code itself should work - although I would probably put some sort of check in place to avoid setting it if you don't need to:

    function onLoad_account() {
        var fax = Xrm.Page.getAttribute("fax").getValue();
        if (fax == null) { 
            Xrm.Page.data.entity.attributes.get("fax").setValue("12345678");
            Xrm.Page.data.entity.save();
        }
    }

    As far as the error - which update roll up are you on?

    You might have a look at this thread: Error :object doesn't support the property or method


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Monday, June 24, 2013 4:43 PM
    Moderator

  • function onLoad_account() {
        Xrm.Page.data.entity.attributes.get("fax").setValue("12345678");
        Xrm.Page.data.entity.save();
     }

    note: this code create a loop

    My blog: www.crmanswers.net

    Monday, June 24, 2013 5:18 PM