I am new to CRM so I can not solve the following.
I have a custom entity "Books". I have a field which is "numberofpages_prefix" integer, what I am trying to do is set the value of another option set field " complexity" with three options "easy" ,"medium" , "hard" depending on the number of pages entered. My event is set onChange and I keep getting the last else statement which is an error message instead of the options. I tried removing the else statement but I am still not getting the value set. Help would be very appreciated.
Here is my code:
*This post is locked for comments
Thank you Ravi, that was the issue.
Very helpful :)
Hi,
Ensure that the schema name of you roptionset field is correct and the value you enter is a numeric value i.e. instead of 976,820,000 try 976820000
Xrm.Page.getAttribute("sonade_c").setValue(976820000);
Hope this helps.
I have tried with those aswell. In my case they are not 1,2,3 but seeing from a tutorial i tried to use 1,2,3 , then I checked the field options and used the ones you mentioned in my case 976,820,000 ,976,820,001, 976,820,002, still did not work
Hello,
To control OptionSet Values via code, you need to set the numeric value associated with the label.
For example if you go the configuration page of your optionset field you will see that each label - easy, medium, hard will be associated with a unique numeric value (for example 1 for easy, 2 for medium and 3 for hard).
If you want to set the value easy for the field you'd need to pass the numeric value as a parameter : Xrm.Page.getAttribute("new_optionfield").setValue(1)
The reason why you need to set the numeric value and not the label is because this gives you the flexibility to change the label in time, without having to change the code as well.
Regards,
Radu
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156