SETSUBMITMODE IN DYNAMICS 365 JAVASCRIPT

In Dynamics 365, there are some scenarios where you want to always submit or never submit the value of a column into the database.

To do this, you have to use the JavaScript method setSubmitMode that will control whether the data for a column is submitted when a record is created or saved.

In case you have a column that you are not interest to capture its data, use the never parameter for the setSubmitMode method.

While, if you want to force a column value to be submitted whether it has changed or not, use the always parameter for the setSubmitMode method.

Use one of the below three options for the setSubmitMode function as per the below.
  1. always: The data is always sent with a create/save event and can be captured within the entity attributes in a plugin
    function setSubmitModeField(context) {
    var formContext = context.getFormContext();
    formContext.getAttribute("primarycontactid").setSubmitMode("always");
    }


    Column's data always captured in the plugin: throw new Exception(account.Contains(Account.Fields.PrimaryContactId).ToString());
    Set submit mode 1

  2. never: The data is never sent with a create/save event and cannot be captured within the entity attributes in a plugin
    For example, if the column is modified and after saving the form, the column's value will be replaced with the old value and will not be submitted.
    function setSubmitModeField(context) {
    var formContext = context.getFormContext();
    formContext.getAttribute("primarycontactid").setSubmitMode("never");
    }


    Column's data never captured in the plugin: throw new Exception(account.Contains(Account.Fields.PrimaryContactId).ToString());
    Set submit mode 2

  3. dirty: This is the default behavior where the data is submitted with the create/save event when the value of the column has changed
    function setSubmitModeField(context) {
    var formContext = context.getFormContext();
    formContext.getAttribute("primarycontactid").setSubmitMode("dirty");
    }

  4. On the other hand, use the function getSubmitMode to return the option indicating when data from the column will be submitted when the record is created/saved

Hope This Helps!

Comments

Popular posts from this blog

DYNAMICS 365 HOW TO HIDE RECENT RECORDS FOR LOOKUP FIELD IN UCI

SEARCH BY GUID IN DYNAMICS 365

SAVE FORM IN DYNAMICS 365 JAVASCRIPT