September 13, 2020

Dependent Option Set Manager


tl;dr: Dependent Option Set Manager Solution (DOSM) can be downloaded here, check the demo here.

First of all, if you contacted me in the past about my previous Dependent Option Set solution and you didn't get an answer I am really sorry.
Only recently I noticed comments on this blog went directly to spam and some of them were about Dependent Option Sets, when I get messages on Twitter or LinkedIn I usually get an email notification and it's easier for me to track them.

Latest release of my previous Dependent Option Set solution was more than 2 years ago, I know it wasn't perfect but the main goal was to easily generate the required JSON, the fact that included also the script to add the functionality to a form was always secondary, I just tweaked the original script to be compatible with more Dynamics versions and with the latest release to make it compatible with Multi Select Option Sets.

If you used or still using it in some projects I am really happy for you, it means it was useful. I am not here to argue or pick a side compared to Filtered Lookups, it happens that sometimes you have Option Sets instead of Lookups (probably the main advantage is the translation of options) and it was nice to provide this functionality.

Microsoft announced Dependent Option Sets before, and I replied to someone asking me about improvements with "Microsoft will release Dependent Option Sets, I don't think I will update my solution". After a while I noticed that Microsoft removed this announcement and my solution (I repeat here, main goal was to generate the required JSON) was still used. In the last years I focused on other projects (Dynamics Weekly and PCF Gallery), I already write code during my working hours and I didn't want to write (crappy) code in public projects. Despite this, I always recognized that my Dependent Option Set solution was used and sooner or later it deserved an update.

I finally decided to spend some time on creating something new and I released Dependent Option Set Manager (DOSM), an updated version of my previous solution. Main reason of this release is the use of formContext instead of the old Xrm.Page, Unified Interface transaction is near (some customers are already using it) and it's nice to provide a fully supported version of the script.

But I wanted to do more, I thought: "How this should work for me?", upgrading the previous JavaScript to support formContext instead of Xrm.Page took me few hours, I changed some parameters, wrote some code and it was ready.
This way still require people to go manually on each form, make the changes, save and publish the form, if you already configured the previous script it's not difficult but it's a tedious process.

I wanted to provide an upgrade path, so people would install the new solution and at least they would have an option to update the forms in one way, and after I wanted to allow users to configure new options, to create new JSON Web Resources and so on.
In the end the new solution has many features so users can do everything inside the app


This forced me to work also on the script attached to the form. Yes, it works in a similar way as the script provided by Microsoft (practically an OnLoad event to load the JSON and an OnChange event for each parent field) but in addition to the code to deal with Multi Select Option Sets and the new features it's something now rewritten by me.

What are these new features?
  • Sorting, you can now decide how the values inside the Option Sets should appears (for example by Label or by Value).
  • Multiple parents, now if a Child Option Set has more than one Parent Option Set, the available options are only the intersect (quick example, for one parent the child options would be A and B, and for another parent options B and C, the only option available would be B).
Solution also included some fixes:
  • It will not trigger when a form is Disabled or Read Only (like inactive records).
  • There was a bug when more than 2 option sets were in a chain and child Option Sets were not cleared when the parent changed.

If you want to try/use the new solution you can go to the Releases under the GitHub repository to download it, and a for a demo here.

The license is MIT, means that the solution is provided "as is", no strings attached, I also tried to make clear this with the notice I wrote inside the tool:

Yes, the code is fully supported, but when dealing with Dynamics XML Forms it's a bit complicated so I needed to make you aware of that warning.

Now regarding support, if you have questions or you have problems with the solution, please open an issue here: https://github.com/GuidoPreite/DOSM/issues
It's better than contacting me directly because
  • I usually get an email when a new issue is opened
  • It's all public so everybody can see it
If in the future Microsoft decides to implement Dependent Option Sets, I only hope they will make an API available, so I can build some tool to convert my solution to the Microsoft one.

The code is public and I tried to make it as much readable as I can, there are many comments both in what the functions do and the code itself.

DOSM uses the following libraries (for the app, the Form script does not have dependencies):
  • jQuery 3.5.1
  • Bootstrap 4.5.0 (I know it's currently 4.5.2 but I didn't feel necessary to upgrade it)
  • Bootbox.js 5.4.0 (to deal with Bootstrap modals)
  • bootstrap-select 1.13.18 (I made a change on this library, the one you find inside DOSM is not the same as you download it, more details in this issue I opened in their repository)