PowerObjects Blog 

for Microsoft Business Applications

Using an OnKeyPress Event to Dynamically Load Values from Global Option Sets

Using an OnKeyPress Event to Dynamically Load Values from Global Option Sets

Post Author: Joe D365 |

Ever wish you could dynamically set the available values of a field to reflect picklist values?

Sure, there are ways of filtering out unwanted options based on some filter criteria, but if you're dealing with data constraints that are constantly changing (ex: the brands of cars sold by a merchant at a particular location) it can get pretty messy, pretty quickly.

That said, the best way to achieve ease of consistency and maintainability when it comes to data is through the use of Global Option Sets and Auto-completion.

First, you'll want to create a Global Option Set that has the values you'd like to leverage.

Next, you'll need to write some JavaScript code that brings in the metadata of the Global Option Set (thanks to the CRM Web API, this is possible):

global option sets

Once that's been completed, we'll want to add some more JavaScript code to our OnLoad event to register our OnKeyPress logic with the appropriate control:

global option sets

Lastly, we'll need to ensure that the text selected matches one of the available picklist values before saving the record:

global option sets

And that should do it!

NOTE: For enhanced performance, you can make "picklistOptions" a global variable, and only populate when/if your picklist selection criteria changes.

Be sure to subscribe to our blog for more helpful Dynamics 365 tips!

Happy Dynamics 365'ing!

By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

PowerObjects Recommends