El propósito de este Jscript es utilizar los WebServices de Microsoft Dynamics CRM para que desde un evento asíncrono en un formulario de CRM cambiar el estado de una actividad “Tarea”.

// Prepare variables.
var EntityId = "6C9E7246-E12D-DE11-8D96-005056C00008";
var TaskState = "Canceled";
var TaskStatus = "6";
var authenticationHeader = GenerateAuthenticationHeader();

// Prepare the SOAP message.
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‘>"+
authenticationHeader+
"<soap:Body>"+
"<Execute xmlns=’http://schemas.microsoft.com/crm/2007/WebServices‘>"+
"<Request xsi:type=’SetStateTaskRequest’>"+
"<EntityId>"+EntityId+"</EntityId>"+
"<TaskState>"+TaskState+"</TaskState>"+
"<TaskStatus>"+TaskStatus+"</TaskStatus>"+
"</Request>"+
"</Execute>"+
"</soap:Body>"+
"</soap:Envelope>";

// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/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);
// Capture the result.
var resultXml = xHReq.responseXML;

// Check for errors.
var errorCount = resultXml.selectNodes(‘//error’).length;
if (errorCount != 0)
{
var msg = resultXml.selectSingleNode(‘//description’).nodeTypedValue;
alert(msg);
}

Nuevo_Logo