web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Forcing form save with javaScript. Only works on new form.

(0) ShareShare
ReportReport
Posted on by

I have a script that forces a (CRM 2011 On-Premise) form to save but it only works when the formType is 1 (new record).

I'm confirming that the form IsDirty and using the 'standard' set of processes for forcing a save.

Extract:

  	myField.setValue(someValue); 
  	myField.setSubmitMode('always');
  	Xrm.Page.data.entity.save();


If getFormType() = 1 it works fine. However, if it is 2 the script throws an error on the 'save' line-

Error: Object does not support this property or method

So I cannot figure out why the Xrm.Page.data.entity object supports 'save' in some scenarios but not in others.

When I debug, I can see 'save' in the list of methods for the Xrm.Page.data.entity object in either scenario.

I have stripped the code back to its bare essentials and applied it to a new, basic custom entity to mitigate any interference from other processes. The error still persists on Edit forms but not on Create.

Several posts suggested to use parent.Xrm.Page.data.entity.save(), but this caused another error-

Error:Unable to get the property 'entity' of undefined or null reference

As you've probably guessed by now, I'm not a developer (no, really!) so would appreciate the assistance of the brains-trust out there.

Has anyone else had this issue and does anyone have a solution?

(JavaScript only please as this is only a workaround until we upgrade to CRM 2016 later this year).

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: Forcing form save with javaScript. Only works on new form.

    Update - I managed to get the script to work on both form types in the custom entity (there was a small field naming error). I will tear down the script in the main entity now and build it up piece by piece (well, maybe not right now as it is 5:30pm on a Friday, but at some point).

  • Rasmus R. Aardal Profile Picture
    on at
    RE: Forcing form save with javaScript. Only works on new form.

    Hello Brad,

    Are you calling the Xrm.Page.data.entity.save() within an onSave-event on the form? I am no developer myself, but from what I can gather that should throw a "Object does not support this property or method"-error.

    If that is the case, you should cancel the "original" save event using JavaScript and apply "your own" save at the bottom of the code.

    Regards,

    Rasmus

  • necsa Profile Picture
    3,455 on at
    RE: Forcing form save with javaScript. Only works on new form.

    Please try it this,

      	myField.setValue(someValue); 
      	myField.setSubmitMode('always');
            crmForm.Save()

    thanks

    Happy CRM


    
                          
  • Community Member Profile Picture
    on at
    RE: Forcing form save with javaScript. Only works on new form.

    Thanks Rasmus,

    Sorry, I should have put this in the original description - I am calling the form-save on load.

    The onload script checks a certain field. If the value is null, the script populates the field and saves the form to trigger a plugin (in theory).

    Then when the form is re-loaded, the field is pre-populated so save is not called again.

  • Saddamk206 Profile Picture
    777 on at
    RE: Forcing form save with javaScript. Only works on new form.

    Hi Please try this code

    //Save Form changes Using JS

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

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Forcing form save with javaScript. Only works on new form.

    Sorry, I should have closed this question 3 months ago. Can't remember the solution and no longer work for that company.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans