title: CRM 2011 - change statecode + statuscode by javascript
body: <p>I want to change statecode and statuscode on ribbon button click in CRM 2011.
  I have javascript function calling SOAP:</p>
  
  <pre><code>if (typeof (Smpl) == "undefined") { Smpl = {}; }
  
  Smpl.Items = {
  change: function () {
  
      var entityId = Xrm.Page.data.entity.getId().substr(1, 36);
      var entityName = Xrm.Page.data.entity.getEntityName();
      var entityState = 0;
      var entityStatus = 100007891;
  
      var xml = "&lt;?xml version='1.0' encoding='utf-8'?&gt;" +
      "&lt;soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'&gt;" +
      "&lt;soap:Body&gt;&lt;Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'&gt;&lt;Request xsi:type='SetStateDynamicEntityRequest'&gt;" +
      "&lt;Entity&gt;&lt;Id xmlns='http://schemas.microsoft.com/crm/2006/CoreTypes'&gt;" + entityId + "&lt;/Id&gt;" +
      "&lt;Name xmlns='http://schemas.microsoft.com/crm/2006/CoreTypes'&gt;" + entityName + "&lt;/Name&gt;&lt;/Entity&gt;" +
      "&lt;State&gt;" + entityState + "&lt;/State&gt;" +
      "&lt;Status&gt;" + entityStatus + "&lt;/Status&gt;" +
      "&lt;/Request&gt;&lt;/Execute&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;";
  
      var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
      xHReq.Open("POST", "http://my.full.com:80/web/mscrmservices/2007/CrmService.asmx", false);
      xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
      xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
      xHReq.setRequestHeader("Content-Length", xml.length);
      xHReq.send(xml);
  
      var resultXml = xHReq.responseXML;
      var errorCount = resultXml.selectNodes('//error').length;
      if (errorCount != 0) {
          var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
          alert(msg);
      }
      window.location.reload();
    }
  }
  </code></pre>
  
  <p>I'd say the whole code is okay, but of course, it's not working at all :/
  On google I found just a few snippets, but nothing different from my code.
  Does not really nobody change status from the ribbon via javascript??</p>
  
  <p>Thank you</p>