// C # code
// Updatestatevaluerequest updatestatevalue = new updatestatevaluerequest
//{
// Attributelogicalname = "statecode ",
// Entitylogicalname = "new_account_product ",
// Value = 1,
// Label = new label ("disabled", 2052)
//};
Function demo (){
// Object Name
VaR entityname = "new_account_product ";
// Attribute name
VaR attrname = "statecode ";
// Value
VaR v = 1;
// Corresponding text
VaR value = "disabled ";
Updatestatevalue (entityname, attrname, V, value );
}
Function updatestatevalue (entityname, attrname, V, value ){
VaR resquest = "<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 = 'a: updatestatevaluerequest 'xmlns: A = 'HTTP: // schemas.microsoft.com/xrm/2011/contracts'>" +
"<A: parameters xmlns: B = 'HTTP: // schemas.datacontract.org/2004/07/system.collections.generic'>" +
"<A: keyvaluepolicrofstringanytype>" +
"<B: Key> value </B: Key>" +
"<B: value I: TYPE = 'C: int' xmlns: c = 'HTTP: // www.w3.org/2001/xmlschema'>" + V + "</B: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"<A: keyvaluepolicrofstringanytype>" +
"<B: Key> mergelabels </B: Key>" +
"<B: value I: TYPE = 'C: boolean' xmlns: c = 'HTTP: // www.w3.org/2001/xmlschema'> false </B: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"<A: keyvaluepolicrofstringanytype>" +
"<B: Key> attributelogicalname </B: Key>" +
"<B: value I: TYPE = 'C: string' xmlns: c = 'HTTP: // www.w3.org/2001/xmlschema'>" + attrname + "</B: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"<A: keyvaluepolicrofstringanytype>" +
"<B: Key> entitylogicalname </B: Key>" +
"<B: value I: TYPE = 'C: string' xmlns: c = 'HTTP: // www.w3.org/2001/xmlschema'>" + entityname + "</B: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"<A: keyvaluepolicrofstringanytype>" +
"<B: Key> label </B: Key>" +
"<B: value I: TYPE = 'a: label'>" +
"<A: localizedlabels>" +
"<A: localizedlabel>" +
"<Metadataid I: Nil = 'true' xmlns = 'HTTP: // schemas.microsoft.com/xrm/2011/metadata'/>" +
"<Haschanged I: Nil = 'true' xmlns = 'HTTP: // schemas.microsoft.com/xrm/2011/metadata'/>" +
"<A: ismanaged I: Nil = 'true'/>" +
"<A: Label>" + value + "</a: Label>" +
"<A: languagecode> 2052 </a: languagecode>" +
"</A: localizedlabel>" +
"</A: localizedlabels>" +
"<A: userlocalizedlabel I: Nil = 'true'/>" +
"</B: value>" +
"</A: keyvaluepolicrofstringanytype>" +
"</A: parameters>" +
"<A: requestid I: Nil = 'true'/>" +
"<A: requestname> updatestatevalue </a: requestname>" +
"</Request>" +
"</Execute>" +
"</S: Body>" +
"</S: envelope> ";
Execsoap (resquest );
}
// 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 ";
}
// Run 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/Delete ");
Ajaxrequest. Send (request );
}
CRM uses soap to change the text value in the drop-down box