Thursday, 31 July 2014

CRM 2013 - Dependent OptionSets (picklists) error onchange

If you like me have downloaded the "Create dependent OptionSets (picklists)" code only to find it does not work in Chrome then never fear!

While i'd like to take responsibility for this fix, i actually found it here. http://ashwaniashwin.wordpress.com/2014/04/27/this-get_editview-is-null-or-not-an-object-error-during-jscript-controls-clearoptions-in-crm-2013/

However if you're lazy then the short answer is for some reason the option set list gets dropped in the following:-
for (var ctrl in controls) {
This means that when we call the following it doesn't exist.
controls[ctrl].clearOptions();
So as mentioned on the post above to fix this you can do the following:-
//controls[ctrl].clearOptions();
var childoptionset = Xrm.Page.ui.controls.get(childField);
childoptionset.clearOptions();
The Dependent OptionSets should now work as required!

Sunday, 13 July 2014

Get Opportunity Won or Lost via JavaScript

Most of you are probably aware of this however I thought i'd put a reminder for myself anyway.

The statecode controls the state of the Opportunity.
statecode label
0Open
1Won
2Lost


And the code I used
var statecode = TryParseInt(Xrm.Page.getAttribute('statecode').getValue(), null);
if (statecode != null)
{
 // Open
 if (statecode == 0)
 {
  // Do Something
 }
 // statecode 1 = Won
 else if (statecode == 1)
 {
  // Do Something
 }
 // statecode 2 = Lost
 else if (statecode == 2)
 {
  // Do Something
 }
 else
 {
  // Handle issue
 }
}