Setting value of Two Options type field
See original GitHub issueIs there a method which allows for the setting of the value of an entity of type ‘Two Options’?
This seems like it should be the right method to call:
xrmBrowser.Entity.SetValue(new OptionSet { Name = "bsp_highrisk", Value = "No" });
but in fact all it does is toggle the existing value.
Here’s a form with four such fields, two have a default Yes, two have a default No:
If we try and set them all to No like this:
xrmBrowser.Entity.SetValue(new OptionSet { Name = "bsp_highrisk", Value = "No" }); xrmBrowser.Entity.SetValue(new OptionSet { Name = "bsp_tradesanctionsapply", Value = "No" }); xrmBrowser.Entity.SetValue(new OptionSet { Name = "bsp_iscountry", Value = "No" }); xrmBrowser.Entity.SetValue(new OptionSet { Name = "bsp_isdemonym", Value = "No" });
we end up with values like this:
and we end up with the same results if we try and set them to Yes.
So I think all that is happening is that the ‘SetValue’ command is selecting the field and thereby toggling the value.
I also tried this:
xrmBrowser.Entity.SetValue("bsp_highrisk", true);
but this does nothing, which is to be expected as this is the method for checkboxes.
I could deal with this by checking the value of the field before changing it, but wondered if there is a better way to do this, or anything coming in a future release to address this.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
Thanks @SantoshDutt - That will work perfectly until the team add a more permanent fix to ‘SetValue’. Maybe I’ll even post a PR if I have time…
Hi @bwmodular,
I have also faced this issue and I am using this below scenario to overcome such risk. You can try this.
string IsCountryOptionPrior = xrmBrowser.Entity.GetValue(new OptionSet { Name = “bsp_iscountry” }); if (IsCountryOptionPrior == “Yes”) { xrmBrowser.Entity.SetValue(new OptionSet { Name = “bsp_iscountry”, Value = “No” }); } Or vice versa if you want any field to set it as Yes.