Get InitialValue of a field in JavaScript – in Dynamics 365 CE

Hi Everyone,

Today I was going through Client API from Microsoft Docs and found getInitialValue reference. I haven’t used it anytime and explored little bit.

Many times we get the requirement to compare the field values on the Save with the values that were populated on the load and to achieve this, normally we use declare a global variable in JavaScript and set the variable to the value of the field on the Load event and use it on Save for comparing. We can say good bye to these kind of logics and use getInitialValue() to get the value when the form is opened.

Here is the syntax for the same.

formContext.getAttribute(<attributename>).getInitialValue()

Note:
1) This method works for only Boolean, OptionSet or MultiSelectOptionSet attributes.
2) Once the record is saved, getInitialValue holds the latest value whatever that was changed by the user.

Hope this helps.


Happy 365’ing
Gopinath.

One thought on “Get InitialValue of a field in JavaScript – in Dynamics 365 CE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s