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
 }
}

No comments:

Post a Comment