Friday 14 August 2020

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.

1 comment:

  1. VueJS is an ideal option to develop an eCommerce store, healthcare apps, financial applications. VueJS has a very small step and scales from just being a little JS library in the app, to a full-fledged SPA structure. Hire Dedicated Vue JS Developer from HireFullStackDeveloperIndia for developing dynamic web applications with VueJS, which is profitable and flexible because it mixes with other JavaScript libraries. They utilize reusable, component-based UI for Vue JS application development and efficiently upscale the applications in the future.

    ReplyDelete