Loading...

SAVE FORM IN DYNAMICS 365 JAVASCRIPT

Image

In Dynamics 365, you may need to save a CRM form automatically in JavaScript upon a specific action on the form.

In order to do that, the function formContext.data.save(saveOptions).then(successCallback, errorCallback); can be used to save the record asynchronously with callback functions to be executed after the save operation is completed.
  1. The following example will display a successful message if the save operation is completed, and a failure message if not.

    formContext.data.save(1).then(
    function () {
    alert("Successfully Saved!");
    },
    function () {
    alert("Failed while saving!");
    });


    form save 1

    form save 2

  2. The save function takes saveOptions as a parameter to specify options for saving the record and has the following properties:
    - saveMode: (Optional) Specify a value indicating how the save event was initiated. Noting that setting the saveMode does not actually take the corresponding action;
    For a list of supported values, see the return value of the getSaveMode method as per following link
    For a full list of the properties, check the following link
  3. successCallback: This function will be called when the operation succeeds.
  4. errorCallback: This function will be called when the operation fails and the following properties will be passed:
    - errorCode: The error code
    - message: A localized error message
Previously, we were able to synchronously save the record using the following script formContext.data.entity.save(saveOption); with the option to close the form or open a new form after the save is completed.
However, this method is now deprecated and it is not recommended to use it anymore.
  1. If no parameter for the save options is passed, the record will simply be saved. This is the same of using the Save command.
  2. saveandclose: This is the same of using the Save and Close command formContext.data.entity.save("saveandclose");
  3. saveandnew: This is the same of using the Save and New command, a new form will be after the save is completed formContext.data.entity.save("saveandnew");


Hope This Helps!
Learn more
Author image

Dynamics 365 Education and Knowledge

Share post:

Related

Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!

* Yes, I agree to the privacy policy