CRM 2011 - change statecode + statuscode by javascript
10,334
For changing state of an entity you need to use the EntityMoniker, in .net in plugins and also in JScript.
Try the code from the following link:
Set Status or State of a Record Using Jscript
Author by
o..o
Updated on June 05, 2022Comments
-
o..o almost 2 years
I want to change statecode and statuscode on ribbon button click in CRM 2011. I have javascript function calling SOAP:
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 = "<?xml version='1.0' encoding='utf-8'?>" + "<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'>" + "<soap:Body><Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'><Request xsi:type='SetStateDynamicEntityRequest'>" + "<Entity><Id xmlns='http://schemas.microsoft.com/crm/2006/CoreTypes'>" + entityId + "</Id>" + "<Name xmlns='http://schemas.microsoft.com/crm/2006/CoreTypes'>" + entityName + "</Name></Entity>" + "<State>" + entityState + "</State>" + "<Status>" + entityStatus + "</Status>" + "</Request></Execute></soap:Body></soap:Envelope>"; 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(); } }
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??
Thank you