Do we still need to use setSubmitMode to save the value of a read-only attribute?

User Review
0 (0 votes)


Before we get to the answer to this question, first we will see what the use of setSubmitMode is. The setSubmitMode is a method to set whether data from the attribute will be submitted when the record is saved.

This method accepts one of the below values as a parameter;

  • Always: If we set as ‘’always’’ then data of the attribute will always be sent with a save. Data will be saved always even though the attribute is not dirty.
  • Never: If we set as ‘’never’’ then data of the attribute will never be sent with a save. Data will not be saved even when value/data of the field is changed. We use this mode when we don’t want to capture the value but want to trigger some logic on change of the attribute.
  • Dirty: This mode will send the data with a save or when it has been changed.

If we ask any CRM developer what is the use of setSubmitMode method along with the aforementioned details we will get one more answer i.e. we have to use setSubmitMode with ‘’always’’ to save the value of read-only attribute. If we have a read-only attribute on the form and want to set the value through script then we would need to write an additional line of code i.e. setSubmitMode with ‘’always’’ parameter.

Xrm.Page.getAttribute("new_availablecredit").setValue(2000); Xrm.Page.getAttribute("new_availablecredit").setSubmitMode("always");

But this have been changed from Dynamics 365 9.x version. Now, we don’t need to use this additional line of code to send the value of the read-only attribute. This is explained in the below link where you can see we are copying the value of “Credit” attribute to read-only “Available Credit” attribute.

And the below code is used on change of “Credit” attribute:

function calculateCredit(context) { try { var formContext = context.getFormContext(); var credit = formContext.getAttribute("creditlimit").getValue(); formContext.getAttribute("new_availablecredit").setValue(credit); } catch (error) { throw new Error(error.message); } }


So basically, the value of the read-only field can be saved without writing an additional setSubmitMode method. Moreover, this also works in both classic web and Unified interface.