text: ﻿"use strict";var RD=window.RD||{__namespace:!0};RD.Libraries=RD.Libraries||{__namespace:!0};typeof RD.Libraries.CustomActionExecutor=="undefined"&&(RD.Libraries.CustomActionExecutor={Execute:function(n){if(n.async!==!0)return this.__ExecuteSync(n);var t=new XMLHttpRequest;t.open("POST",RD.Libraries.CustomActionExecutor.GetServiceUrl(),!!n.async);try{t.responseType="msxml-document"}catch(i){}t.setRequestHeader("Accept","application/xml, text/xml, */*");t.setRequestHeader("Content-Type","text/xml; charset=utf-8");t.setRequestHeader("SOAPAction","http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");t.onreadystatechange=function(){t.readyState==4&&(t.status==200?RD.Libraries.CustomActionExecutor.ProcessSoapResponse(t.responseXML,n.successCallback,n.errorCallback):n.errorCallback(RD.Libraries.CustomActionExecutor.ProcessSoapError(t.responseXML)))};t.send(n.requestXml)},__ExecuteSync:function(n){var t=new XMLHttpRequest;t.open("POST",RD.Libraries.CustomActionExecutor.GetServiceUrl(),!!n.async);try{t.responseType="msxml-document"}catch(i){}return t.setRequestHeader("Accept","application/xml, text/xml, */*"),t.setRequestHeader("Content-Type","text/xml; charset=utf-8"),t.setRequestHeader("SOAPAction","http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute"),t.send(n.requestXml),t.status==200&&t.responseXML!=null?RD.Libraries.CustomActionExecutor.ProcessSoapResponse(t.responseXML):t.responseXML!=null?RD.Libraries.CustomActionExecutor.ProcessSoapError(t.responseXML):"Error!"},GenerateActionXML:function(n,t,i,r,u){var f="",e;if(f+='<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">',f+="  <s:Body>",f+='    <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">',f+='      <request xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">',f+='        <a:Parameters xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">',t!=null&&i!=null)f+="          <a:KeyValuePairOfstringanyType>",f+="            <b:key>Target<\/b:key>",f+='            <b:value i:type="a:EntityReference">',f+="              <a:Id>"+t+"<\/a:Id>",f+="              <a:LogicalName>"+i+"<\/a:LogicalName>",f+='              <a:Name i:nil="true" />',f+="            <\/b:value>",f+="          <\/a:KeyValuePairOfstringanyType>";else if(u==!0)return"A target is required! (for global actions try using the current user id.)";for(e in r)f+="          <a:KeyValuePairOfstringanyType>",f+="            <b:key>"+r[e].key+"<\/b:key>",r[e].type=="EntityReference"?(f+='            <b:value i:type="a:EntityReference">',f+="              <a:Id>"+r[e].entityId+"<\/a:Id>",f+="              <a:LogicalName>"+r[e].entityName+"<\/a:LogicalName>",f+='              <a:Name i:nil="true" />',f+="            <\/b:value>"):f+='            <b:value i:type="c:'+r[e].type+'" xmlns:c="http://www.w3.org/2001/XMLSchema">'+r[e].value+"<\/b:value>",f+="          <\/a:KeyValuePairOfstringanyType>";return f+="        <\/a:Parameters>",f+='        <a:RequestId i:nil="true" />',f+="        <a:RequestName>"+n+"<\/a:RequestName>",f+="      <\/request>",f+="    <\/Execute>",f+="  <\/s:Body>",f+"<\/s:Envelope>"},ProcessSoapResponse:function(n,t){var r,i;try{r=["xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'","xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts'","xmlns:i='http://www.w3.org/2001/XMLSchema-instance'","xmlns:b='http://schemas.microsoft.com/crm/2011/Contracts'","xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic'"];n.setProperty("SelectionNamespaces",r.join(" "))}catch(u){}if(i=RD.Libraries.CustomActionExecutor._selectNodes(n,"//a:Results/a:KeyValuePairOfstringanyType"),typeof t!="undefined")t(RD.Libraries.CustomActionExecutor.ObjectifyNodes(i));else return RD.Libraries.CustomActionExecutor.ObjectifyNodes(i)},ProcessSoapError:function(n){var t,i;try{t=["xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'","xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts'","xmlns:i='http://www.w3.org/2001/XMLSchema-instance'","xmlns:b='http://schemas.microsoft.com/crm/2011/Contracts'","xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic'"];n.setProperty("SelectionNamespaces",t.join(" "))}catch(r){}return i=RD.Libraries.CustomActionExecutor._selectSingleNode(n,"//s:Fault/faultstring"),new Error(RD.Libraries.CustomActionExecutor._getNodeText(i))},ObjectifyNodes:function(n){for(var r,u,i={},t=0;t<n.length;t++)r=RD.Libraries.CustomActionExecutor._getNodeText(n[t].firstChild),u=n[t].childNodes[1],i[r]=RD.Libraries.CustomActionExecutor.ObjectifyNode(u);return i},ObjectifyNode:function(n){if(n.attributes!=null){if(n.attributes.getNamedItem("i:nil")!=null&&n.attributes.getNamedItem("i:nil").nodeValue=="true")return null;var t=n.attributes.getNamedItem("i:type")==null?"c:string":n.attributes.getNamedItem("i:type").nodeValue;switch(t){case"a:EntityReference":return RD.Libraries.CustomActionExecutor.ObjectifyEntityReference(n);case"a:Entity":return RD.Libraries.CustomActionExecutor.ObjectifyRecord(n);case"a:EntityCollection":return RD.Libraries.CustomActionExecutor.ObjectifyCollection(n.firstChild);case"c:dateTime":return RD.Libraries.CustomActionExecutor.ParseIsoDate(RD.Libraries.CustomActionExecutor._getNodeText(n));case"c:guid":case"c:string":return RD.Libraries.CustomActionExecutor._getNodeText(n);case"c:int":return parseInt(RD.Libraries.CustomActionExecutor._getNodeText(n));case"a:OptionSetValue":return parseInt(RD.Libraries.CustomActionExecutor._getNodeText(n.childNodes[0]));case"c:boolean":return RD.Libraries.CustomActionExecutor._getNodeText(n.childNodes[0])=="true";case"c:double":case"c:decimal":case"a:Money":return parseFloat(RD.Libraries.CustomActionExecutor._getNodeText(n.childNodes[0]));default:return null}}return null},ObjectifyEntityReference:function(n){for(var t={id:"",entityType:""},i=0;i<n.childNodes.length;i++){switch(n.childNodes[i].tagName){case"a:Id":t.id=RD.Libraries.CustomActionExecutor._getNodeText(n.childNodes[i]);break;case"a:LogicalName":t.entityType=RD.Libraries.CustomActionExecutor._getNodeText(n.childNodes[i])}if(t.id&&t.entityType)break}return t},ObjectifyCollection:function(n){for(var i=[],t=0;t<n.childNodes.length;t++)i.push(RD.Libraries.CustomActionExecutor.ObjectifyRecord(n.childNodes[t]));return i},ObjectifyRecord:function(n){var t={};return t.logicalName=n.childNodes[4].text!==undefined?n.childNodes[4].text:n.childNodes[4].textContent,t.id=n.childNodes[3].text!==undefined?n.childNodes[3].text:n.childNodes[3].textContent,t.attributes=RD.Libraries.CustomActionExecutor.ObjectifyNodes(n.childNodes[0].childNodes),t.formattedValues=RD.Libraries.CustomActionExecutor.ObjectifyNodes(n.childNodes[2].childNodes),t},ParseIsoDate:function(n){if(n==null||!n.match(RD.Libraries.CustomActionExecutor.isoDateExpression))return null;var t=RD.Libraries.CustomActionExecutor.isoDateExpression.exec(n);return new Date(Date.UTC(parseInt(t[1],10),parseInt(t[2],10)-1,parseInt(t[3],10),parseInt(t[4],10)-(t[8]==""||t[8]=="Z"?0:parseInt(t[8])),parseInt(t[5],10),parseInt(t[6],10)))},GetServiceUrl:function(){var n=null;return typeof GetGlobalContext=="function"?n=GetGlobalContext():typeof Xrm!="undefined"&&(n=Xrm.Page.context),n.getClientUrl()+"/XRMServices/2011/Organization.svc/web"},_selectNodes:function(n,t){if(typeof n.selectNodes!="undefined")return n.selectNodes(t);for(var r=[],u=n.evaluate(t,n,RD.Libraries.CustomActionExecutor._NSResolver,XPathResult.ANY_TYPE,null),i=u.iterateNext();i;)r.push(i),i=u.iterateNext();return r},_selectSingleNode:function(n,t){if(typeof n.selectSingleNode!="undefined")return n.selectSingleNode(t);var r=new XPathEvaluator,i=r.evaluate(t,n,RD.Libraries.CustomActionExecutor._NSResolver,XPathResult.FIRST_ORDERED_NODE_TYPE,null);return i!=null?i.singleNodeValue:null},_getNodeText:function(n){return typeof n.text!="undefined"?n.text:n.textContent},_isNodeNull:function(n){return n==null?!0:n.attributes.getNamedItem("i:nil")!=null&&n.attributes.getNamedItem("i:nil").value=="true"?!0:!1},_getNodeName:function(n){return typeof n.baseName!="undefined"?n.baseName:n.localName},_NSResolver:function(n){return{s:"http://schemas.xmlsoap.org/soap/envelope/",a:"http://schemas.microsoft.com/xrm/2011/Contracts",i:"http://www.w3.org/2001/XMLSchema-instance",b:"http://schemas.microsoft.com/crm/2011/Contracts",c:"http://schemas.datacontract.org/2004/07/System.Collections.Generic"}[n]||null},isoDateExpression:/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.?(\d*)?(Z|[+-]\d{2}?(:\d{2})?)?$/,__namespace:!0});