首页 > 代码库 > crm使用soap更改下拉框的文本值
crm使用soap更改下拉框的文本值
//C#代码
//UpdateStateValueRequest updateStateValue = http://www.mamicode.com/new UpdateStateValueRequest
//{
// AttributeLogicalName = "statecode",
// EntityLogicalName = "new_account_product",
// Value = http://www.mamicode.com/1,
// Label = new Label("关闭了", 2052)
//};
function demo() {
//实体名称
var entityname = "new_account_product";
//属性名称
var attrname = "statecode";
//值
var v = 1;
//相应文本
var value = http://www.mamicode.com/"关闭了";
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:KeyValuePairOfstringanyType>" +
"<b:key>Value</b:key>" +
"<b:value i:type=‘c:int‘ xmlns:c=‘http://www.w3.org/2001/XMLSchema‘>"+ v +"</b:value>" +
"</a:KeyValuePairOfstringanyType>" +
"<a:KeyValuePairOfstringanyType>" +
"<b:key>MergeLabels</b:key>" +
"<b:value i:type=‘c:boolean‘ xmlns:c=‘http://www.w3.org/2001/XMLSchema‘>false</b:value>" +
"</a:KeyValuePairOfstringanyType>" +
"<a:KeyValuePairOfstringanyType>" +
"<b:key>AttributeLogicalName</b:key>" +
"<b:value i:type=‘c:string‘ xmlns:c=‘http://www.w3.org/2001/XMLSchema‘>" + attrname + "</b:value>" +
"</a:KeyValuePairOfstringanyType>" +
"<a:KeyValuePairOfstringanyType>" +
"<b:key>EntityLogicalName</b:key>" +
"<b:value i:type=‘c:string‘ xmlns:c=‘http://www.w3.org/2001/XMLSchema‘>"+ entityname +"</b:value>" +
"</a:KeyValuePairOfstringanyType>" +
"<a:KeyValuePairOfstringanyType>" +
"<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:KeyValuePairOfstringanyType>" +
"</a:Parameters>" +
"<a:RequestId i:nil=‘true‘ />" +
"<a:RequestName>UpdateStateValue</a:RequestName>" +
"</request>" +
"</Execute>" +
"</s:Body>" +
"</s:Envelope>";
execSoap(resquest);
}
//获取服务地址
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";
}
//运行请求
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使用soap更改下拉框的文本值