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).