When I needed to create some dependent option sets for a client in Dynamics CRM, I knew where to start: GOOGLE. One of the top results for solving this issue, was this MSDN sample: https://msdn.microsoft.com/en-us/library/gg594433.aspx
The provided sample solutions worked like a charm. Time to implement it in my real world scenario. The documentation on the MSDN sample page clearly states that the label values in the xml are solely there for readability purposes. They are NOT used in the script.
Well, I don’t like typing too much, so when creating my own xml, I left out each and any label attributes.
Imagine my surprise when I used this on my form and the result of the dependent option sets looked like this:
At first I thought I made a mistake and started going through my xml. Except for having no label attributes whatsoever, the file was ok. That’s when the developer in me started going through the actual code. And surely, while the sample documentation states that the label values are not used. They are …
Luckily, there’s just a little bit of extra code needed to make this work as promised.
These steps are necessary to make this work:
- During the initialize stage, get a hold of the original option set values of the dependent option sets. They will be in the correct language, provided that translations are in place in your environment.
- When creating the options array for each parent item, get the label from the original option set value that we retrieved in step 1.
- In the interest of readability, write a separate function to do the search necessary in step 2.
The code before the change:
The code after the change:
I left the option to set a label value provided in the xml, just in case the translated text is not found. Which for me would result in null labels again, but hey, I will configure this correctly so it won’t be needed, right?
The result after changing the script:
This concludes this blog post, hope it helps!