// C # code
// Entity target = new entity () {logicalname = "opportunityclose "};
// Target ["opportunityid"] =
// New entityreference () {logicalname = "opportunity", id = new GUID ("F56B88B7-D412-E411-9405-00155D005808 ")};
// Target ["actualrevenue"] = new money (10 );
// Target ["actualend"] = datetime. now;
// Target ["Description"] = "test ";
// Loseopportunityrequest request = new loseopportunityrequest ();
// Request. opportunityclose = target;
// Request. Status = new optionsetvalue (4 );
// JS calls using soap
Function deom (){
// Business opportunity ID
VaR opportunityid = "F56B88B7-D412-E411-9405-00155D005808 ";
// Actual income
VaR actualrevenue = 10;
// End the actual
VaR actualend = "2014-07-24t12: 49: 52.6654687 + 08: 00 ";
// Description
VaR description = "test ";
// Status
VaR state = 4;
// Ticket loss
Loseopportunity (opportunityid, actualrevenue, actualend, description, State );
}
Function loseopportunity (opportunityid, actualrevenue, actualend, description, state ){
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: loseopportunityrequest' 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> opportunityclose </C: Key>" +
"<C: value I: TYPE = 'a: entity '>" +
"<A: Attributes>" +
"<A: keyvaluepolicrofstringanytype>" +
"<C: Key> opportunityid </C: Key>" +
"<C: value I: TYPE = 'a: entityreference '>" +
"<A: Id>" + opportunityid + "</a: Id>" +
"<A: logicalname> opportunity </a: logicalname>" +
"<A: Name I: Nil = 'true'/>" +
"</C: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"<A: keyvaluepolicrofstringanytype>" +
"<C: Key> actualrevenue </C: Key>" +
"<C: value I: TYPE = 'a: money'>" +
"<A: value>" + actualrevenue + "</a: value>" +
"</C: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"<A: keyvaluepolicrofstringanytype>" +
"<C: Key> actualend </C: Key>" +
"<C: value I: TYPE = 'd: datetime 'xmlns: D = 'HTTP: // www.w3.org/2001/xmlschema'>" + actualend + "</C: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"<A: keyvaluepolicrofstringanytype>" +
"<C: Key> description </C: Key>" +
"<C: value I: TYPE = 'd: String 'xmlns: D = 'HTTP: // www.w3.org/2001/xmlschema'>" + description + "</C: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"</A: Attributes>" +
"<A: entitystate I: Nil = 'true'/>" +
"<A: formattedvalues/>" +
"<A: Id> 00000000-0000-0000-0000-000000000000 </a: Id>" +
"<A: logicalname> opportunityclose </a: logicalname>" +
"<A: relatedentities/>" +
"</C: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"<A: keyvaluepolicrofstringanytype>" +
"<C: Key> Status </C: Key>" +
"<C: value I: TYPE = 'a: optionsetvalue'>" +
"<A: value>" + state + "</a: value>" +
"</C: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"</A: parameters>" +
"<A: requestid I: Nil = 'true'/>" +
"<A: requestname> loseopportunity </a: requestname>" +
"</Request>" +
"</Execute>" +
"</S: Body>" +
"</S: envelope> ";
Execsoap (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 );
}