https://community.dynamics.com/crm/b/crminogic/archive/2013/09/27/introduction-to-actions-in-crm-2013
Added asynchronous call.
if (typeof (SDK) == "undefined")
{ SDK = { __namespace: true }; }
SDK.Action = {
_getClientUrl: function () {
var ServicePath = "/XRMServices/2011/Organization.svc/web";
var clientUrl = "";
if (typeof GetGlobalContext == "function") {
var context = GetGlobalContext();
clientUrl = context.getClientUrl();
}
else {
if (typeof Xrm.Page.context == "object") {
clientUrl = Xrm.Page.context.getClientUrl();
}
else { throw new Error("Unable to access the server URL"); }
}
if (clientUrl.match(/\/$/)) {
clientUrl = clientUrl.substring(0, clientUrl.length - 1);
}
return clientUrl + ServicePath;
},
ApproveRequest: function () {
var salesOrderId = Xrm.Page.data.entity.getId();
var approvedById = Xrm.Page.context.getUserId();
var requestMain = ""
requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
requestMain += " <s:Body>";
requestMain += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestMain += " <request xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
requestMain += " <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <b:key>Target</b:key>";
requestMain += " <b:value i:type=\"a:EntityReference\">";
requestMain += " <a:Id>" + salesOrderId + "</a:Id>";
requestMain += " <a:LogicalName>incident</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += " </b:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <b:key>EscalatedBy</b:key>";
requestMain += " <b:value i:type=\"a:EntityReference\">";
requestMain += " <a:Id>" + approvedById + "</a:Id>";
requestMain += " <a:LogicalName>systemuser</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += " </b:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Parameters>";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>new_Escalate</a:RequestName>";
requestMain += " </request>";
requestMain += " </Execute>";
requestMain += " </s:Body>";
requestMain += "</s:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", SDK.Action._getClientUrl(), true)
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
req.send(requestMain);
//req.onreadystatechange = SDK.Action.ShowResponse;
//work with the response here
//var strResponse = req.responseXML.xml;
},
ShowResponse: function ()
{
var x = req.responseXML.getElementsByTagName(" a:KeyValuePairOfstringany Type");
for (i = 0; i < x.length; i ++)
{
if (x[ i]. childNodes[ 0]. textContent == "Priority")
{ alert(" The case has been assigned to " + x[ i]. childNodes[ 1]. textContent + " priority.");
}
}
},
__namespace: true
};
No comments:
Post a Comment