Function demo (){
// Operation record ID
VaR targetid = "a8a46444-ba10-e411-8a04-00155d002f02 ";
// Object Name of the operation record
VaR targettype = "new_config ";
// Enable
Setstate (targetid, targettype, 1, 2 );
// Disable
Setstate (targetid, targettype, 0, 1 );
}
Function setstate (targetid, targettype, state, status ){
VaR request = "<s: envelope xmlns: S = 'HTTP: // schemas.xmlsoap.org/soap/envelope/'>" +
"<S: Body>" +
"<Execute xmlns = 'HTTP: // schemas.microsoft.com/xrm/2011/contracts/services'xmlns: I = 'HTTP: // www.w3.org/2001/xmlschema-instance'>" +
"<Request I: TYPE = 'B: setstaterequest' xmlns: A = 'HTTP: // your xmlns: B = 'HTTP: // schemas.microsoft.com/crm/2011/contracts'>" +
"<A: parameters xmlns: c = 'HTTP: // schemas.datacontract.org/2004/07/system.collections.generic'>" +
"<A: keyvaluepolicrofstringanytype>" +
"<C: Key> entitymoniker </C: Key>" +
"<C: value I: TYPE = 'a: entityreference '>" +
"<A: Id>" + targetid + "</a: Id>" +
"<A: logicalname>" + targettype + "</a: logicalname>" +
"<A: Name I: Nil = 'true'/>" +
"</C: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"<A: keyvaluepolicrofstringanytype>" +
"<C: Key> state </C: Key>" +
"<C: value I: TYPE = 'a: optionsetvalue'>" +
"<A: value>" + state + "</a: value>" +
"</C: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"<A: keyvaluepolicrofstringanytype>" +
"<C: Key> Status </C: Key>" +
"<C: value I: TYPE = 'a: optionsetvalue'>" +
"<A: value>" + status + "</a: value>" +
"</C: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"</A: parameters>" +
"<A: requestid I: Nil = 'true'/>" +
"<A: requestname> setstate </a: requestname>" +
"</Request>" +
"</Execute>" +
"</S: Body> ";
"</S: envelope> ";
Getweburl (request );
}
// Obtain the service address
Function getweburl (){
VaR serverurl = xrm. Page. Context. getserverurl ();
If (serverurl. Match (// $ /)){
Serverurl = serverurl. substring (0, serverurl. Length-1 );
}
Return serverurl + "/xrmservices/2011/organization. svc/Web ";
}
// Execute the request
Function execsoap (request ){
VaR ajaxrequest = new XMLHttpRequest ();
Ajaxrequest. Open ("Post", getweburl (), true)
Ajaxrequest. setRequestHeader ("accept", "application/XML, text/XML ,*/*");
Ajaxrequest. setRequestHeader ("Content-Type", "text/XML; charset = UTF-8 ");
Ajaxrequest. setRequestHeader ("soapaction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute ");
Ajaxrequest. Send (request );
}
Use soap to enable and disable CRM records