Get initial value of a field in Dynamics 365/CDS form using Client API

This is one of the most common requirement which you come across in your Dynamics 365 implementations. For example – you may have a requirement where you need to determine the initial value of a field when the record is opened. So that if the user have changed the value to something else, you can perform some custom business validations using depending on the initial value and final value.

For this you can use the a function in the API which has been introduced sometime back. The method is – formContext.getAttribute(<attributename>).getInitialValue()

Few important considerations before you use getInitialValue() method

  • The method is only available for Boolean, OptionSet and Multi-select option set as of the time of writing this blog
  • getInitialValue() will return the value since the record was last saved. Example – you have an optionset field – Field X on the form. When you open the record, the value of the field is “A”. User changes it to “B”. getInitialValue() will still return “A”. Now if you save the record- getInitialValue() will return “B”.

Hope this helps!

Debajit Dutta

(Business Solutions MVP)