// Batch delete data
Function demo (){
// Object Name
VaR entityname = "fw_student ";
VaR DATA = [];
Data. Push ("8b1d93c6-bf1e-e411-9406-00155d005802 ");
Data. Push ("20718494-0c2c-e411-9407-00155d005802 ");
Executemultipledelete (entityname, data );
}
Function executemultipledelete (name, iddata ){
VaR request = "<s: envelope xmlns: S = 'HTTP: // schemas.xmlsoap.org/soap/envelope/'> ";
Request + = "<s: Body> ";
Request + = "<execute xmlns = 'HTTP: // schemas.microsoft.com/xrm/2011/contracts/services'xmlns: I = 'HTTP: // www.w3.org/2001/xmlschema-instance'> ";
Request + = "<request I: TYPE = 'a: executemultiplerequest 'xmlns: A = 'HTTP: // schemas.microsoft.com/xrm/2011/contracts'> ";
Request + = "<A: parameters xmlns: B = 'HTTP: // schemas.datacontract.org/2004/07/system.collections.generic'> ";
Request + = "<A: keyvaluepolicrofstringanytype> ";
Request + = "<B: Key> requests </B: Key> ";
Request + = "<B: value I: TYPE = 'C: organizationrequestcollection 'xmlns: c = 'HTTP: // schemas.microsoft.com/xrm/2012/contracts'> ";
VaR Len = iddata. length;
For (VAR I = 0; I <Len; I ++ ){
Additem (name, iddata [I]);
}
Request + = "</B: value> ";
Request + = "</a: keyvaluepolicrofstringanytype> ";
Request + = "<A: keyvaluepolicrofstringanytype> ";
Request + = "<B: Key> Settings </B: Key> ";
Request + = "<B: value I: TYPE = 'C: executemultiplesettings 'xmlns: c = 'HTTP: // schemas.microsoft.com/xrm/2012/contracts'> ";
Request + = "<C: continueonerror> false </C: continueonerror> ";
Request + = "<C: returnresponses> true </C: returnresponses> ";
Request + = "</B: value> ";
Request + = "</a: keyvaluepolicrofstringanytype> ";
Request + = "</a: parameters> ";
Request + = "<A: requestid I: Nil = 'true'/> ";
Request + = "<A: requestname> executemultiple </a: requestname> ";
Request + = "</request> ";
Request + = "</execute> ";
Request + = "</S: Body> ";
Request + = "</S: envelope> ";
Execsoap (request );
}
Function additem (name, ID ){
VaR request = "<C: organizationrequest I: TYPE = 'a: deleterequest '> ";
Request + = "<A: parameters> ";
Request + = "<A: keyvaluepolicrofstringanytype> ";
Request + = "<B: Key> Target </B: Key> ";
Request + = "<B: value I: TYPE = 'a: entityreference '> ";
Request + = "<A: Id>" + ID + "</a: Id> ";
Request + = "<A: logicalname>" + name + "</a: logicalname> ";
Request + = "<A: Name I: Nil = 'true'/> ";
Request + = "</B: value> ";
Request + = "</a: keyvaluepolicrofstringanytype> ";
Request + = "</a: parameters> ";
Request + = "<A: requestid I: Nil = 'true'/> ";
Request + = "<A: requestname> Delete </a: requestname> ";
Request + = "</C: organizationrequest> ";
Return 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 );
}
Batch delete data using soap in CRM