//C#代码

//#region OptionMetadataCollection

//OptionMetadataCollection opCollection = new OptionMetadataCollection();

//opCollection.Add(new OptionMetadata(new Label("2000年", languageCode), 2000));

//opCollection.Add(new OptionMetadata(new Label("2001年", languageCode), 2001));

//opCollection.Add(new OptionMetadata(new Label("2002年", languageCode), 2002));

//opCollection.Add(new OptionMetadata(new Label("2003年", languageCode), 2003));

//opCollection.Add(new OptionMetadata(new Label("2004年", languageCode), 2004));

//opCollection.Add(new OptionMetadata(new Label("2005年", languageCode), 2005));

//#endregion

//OptionSetMetadata optionSet = new OptionSetMetadata(opCollection);

//optionSet.Name = "new_year";

//optionSet.Description = new Label("年份", languageCode);

//optionSet.DisplayName = new Label("年份", languageCode);

//optionSet.IsGlobal = true;

//optionSet.OptionSetType = OptionSetType.Picklist;

//CreateOptionSetRequest request = new CreateOptionSetRequest();

//request.OptionSet = optionSet;

//CreateOptionSetResponse response = (CreateOptionSetResponse)service.Execute(request);

//样例

function demo() {

    //字段名称

    var attrName = "new_year";

    //标签

    var labelName = "年份";

    //语言编码

    var code = 2052;

    //集合

    var dataArray = [];

    dataArray.push(getOptionItem("2000年", 2000));

    dataArray.push(getOptionItem("2001年", 2001));

    dataArray.push(getOptionItem("2002年", 2002));

    dataArray.push(getOptionItem("2003年", 2003));

    dataArray.push(getOptionItem("2004年", 2004));

    dataArray.push(getOptionItem("2005年", 2005));

    dataArray.push(getOptionItem("2006年", 2006));

createOption(attrName, labelName, code, dataArray);


   

}

function getOptionItem(name, value) {

    var item = new Object();

    item.name = name;

    item.value = value;

    return item;

}

function createOption(attrName,labelName,code,dataArray) {

    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:CreateOptionSetRequest' 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:KeyValuePairOfstringanyType>";

    request += "<b:key>OptionSet</b:key>";

    request += "<b:value i:type='c:OptionSetMetadata' xmlns:c='http://schemas.microsoft.com/xrm/2011/Metadata'>";

    request += "<c:MetadataId i:nil='true' />";

    request += "<c:HasChanged i:nil='true' />";

    request += "<c:Description>";

    request += "<a:LocalizedLabels>";

    request += "<a:LocalizedLabel>";

    request += "<c:MetadataId i:nil='true' />";

    request += "<c:HasChanged i:nil='true' />";

    request += "<a:IsManaged i:nil='true' />";

    request += "<a:Label>"+ labelName +"</a:Label>";

    request += "<a:LanguageCode>2052</a:LanguageCode>";

    request += "</a:LocalizedLabel>";

    request += "</a:LocalizedLabels>";

    request += "<a:UserLocalizedLabel i:nil='true' />";

    request += "</c:Description>";

    request += "<c:DisplayName>";

    request += "<a:LocalizedLabels>";

    request += "<a:LocalizedLabel>";

    request += "<c:MetadataId i:nil='true' />";

    request += "<c:HasChanged i:nil='true' />";

    request += "<a:IsManaged i:nil='true' />";

    request += "<a:Label>"+ labelName +"</a:Label>";

    request += "<a:LanguageCode>2052</a:LanguageCode>";

    request += "</a:LocalizedLabel>";

    request += "</a:LocalizedLabels>";

    request += "<a:UserLocalizedLabel i:nil='true' />";

    request += " </c:DisplayName>";

    request += "<c:IsCustomOptionSet i:nil='true' />";

    request += "<c:IsCustomizable i:nil='true' />";

    request += "<c:IsGlobal>true</c:IsGlobal>";

    request += "<c:IsManaged i:nil='true' />";

    request += "<c:Name>"+ attrName +"</c:Name>";

    request += "<c:OptionSetType>Picklist</c:OptionSetType>";

    request += "<c:Options> ";

    //加入详细的每一小项

    if (dataArray != null && dataArray.length > 0) {

        var len = dataArray.length;

        for (var i = 0; i < len; i++) {

            var item = dataArray[i];

            request += getItem(item.name, item.value, code);

        }

    }

    request += "</c:Options>";

    request += "</b:value>";

    request += "</a:KeyValuePairOfstringanyType>";

    request += "</a:Parameters>";

    request += "<a:RequestId i:nil='true' />";

    request += "<a:RequestName>CreateOptionSet</a:RequestName>";

    request += "</request>";

    request += "</Execute>";

    request += "</s:Body>";

    request += "</s:Envelope>";

execSoap(request);

}

function getItem(name,value,code) {

    var request = "<c:OptionMetadata>";

    request += "<c:MetadataId i:nil='true' />";

    request += "<c:HasChanged i:nil='true' />";

    request += "<c:Description i:nil='true' />";

    request += "<a:IsManaged i:nil='true' />";

    request += "<c:Label>";

    request += "<a:LocalizedLabels>";

    request += "<a:LocalizedLabel>";

    request += "<c:MetadataId i:nil='true' />";

    request += "<c:HasChanged i:nil='true' />";

    request += "<a:IsManaged i:nil='true' />";

    request += "<a:Label>" + name + "</a:Label>";

    request += "<a:LanguageCode>"+ code +"</a:LanguageCode>";

    request += "</a:LocalizedLabel>";

    request += "</a:LocalizedLabels>";

    request += "<a:UserLocalizedLabel i:nil='true' />";

    request += "</c:Label>";

    request += "<c:Value>"+ value +"</c:Value>";

    request += "</c:OptionMetadata>";

    return request;

}

//获取服务地址

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/Execute");

    ajaxRequest.send(request);

}

crm使用soap创建下拉框的更多相关文章

  1. crm使用soap更改下拉框的文本值

    //C#代码 //UpdateStateValueRequest updateStateValue = new UpdateStateValueRequest //{ //    AttributeL ...

  2. crm使用soap插入下拉框选项

    //C# 代码: //InsertOptionValueRequest request = new InsertOptionValueRequest(); //request.OptionSetNam ...

  3. crm使用soap删除下拉框

    //C# 代码: //DeleteOptionSetRequest request = new DeleteOptionSetRequest(); //request.Name = "new ...

  4. 使用ng-options指令创建下拉框

    今天在学习AngularJs中使用ng-options指令创建下拉框时遇到点问题,这里总结一下. 其实,使用ng-options指令创建下拉框很简单,只需要绑定两个属性. ng-options指令用于 ...

  5. layui 根据根据后台数据动态创建下拉框并同时默认选中

        第一步 form表单里写好一个下拉框 <div class="layui-form-item"> <label class="layui-for ...

  6. jQuery无限级联下拉框插件

    自己编写jQuery插件 之 无限级联下拉框   因为是级联,所以数据必须是树型结构的,我这里的测试数据如下: 看下效果图: 1.>图一: 2.>图二: 3.>图三: 由图可知,下拉 ...

  7. java操作poi生成excel.xlsx(设置下拉框)下载本地和前端下载

    需求:导入excel表格,如果excel有错误,将错误的地方标红,在把数据以excel的形式写出,供用户下载解决方案:1.以实体类的方式接收excel并解析(创建两个集合一个接收正常的数据一个接收错误 ...

  8. vue自定义下拉框组件

    创建下拉框组件 Select.vue <template> <div class="selects"> <div :class="{sele ...

  9. 雷林鹏分享:jQuery EasyUI 表单 - 创建树形下拉框

    jQuery EasyUI 表单 - 创建树形下拉框 树形下拉框(ComboTree)是一个带有下列树形结构(Tree)的下拉框(ComboBox).它可以作为一个表单字段进行使用,可以提交给远程服务 ...

随机推荐

  1. shell脚本书写总结

    1.shell脚本,如果重定向到文件中,则在脚本中不可以sed -i,如果用了sed -i ,则自打用了sed -i之后的打印都不能再重定向到输出文件了. 2.shell脚本中,如果将命令写在字符串里 ...

  2. 【转】android电池(五):电池 充电IC(PM2301)驱动分析篇

    关键词:android 电池  电量计  PL2301任务初始化宏 power_supply 中断线程化 平台信息:内核:linux2.6/linux3.0系统:android/android4.0  ...

  3. IOS7 UITableView一行滑动删除后 被删除行的下一行的点击事件将被忽略解决办法

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSI ...

  4. IOS MVC

    简单的理解: V对M是不能通讯的. C对M通讯:API M对C通讯:Notification,KVO C对V通讯:Outlet V对C通讯:Target-action, Delegate,Dataso ...

  5. PHP学习笔记十二【数组排序】

    <?php $arr=array(0,5,-1); $temp=0; for($i=0;$i<count($arr)-1;$i++) { for($j=0;$j<count($arr ...

  6. Reverse Words in a String (JAVA)

    Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...

  7. (ssh整合web导出excel)在ssh框架中使用poi正确导出具有比较高级固定格式的excel 整体过程,查询导出前后台下载

    (一) 接需求  :   需求相关   (贴图 ) 生成三核对文件 1.新增三核对菜单页面中,增加生成三核对文件功能按钮,弹窗可根据变电站.电压等级查询定值单. 2.定值单信息以表格形式展示,根据选择 ...

  8. linux常用命令--diff

    diff是Unix系统的一个很重要的工具程序. 它用来比较两个文本文件的差异,是代码版本管理的基石之一.你在命令行下,输入: $ diff <变动前的文件> <变动后的文件> ...

  9. C期未考试参考答案题1

    输入一个3行5列的矩阵数据,输出矩阵中每行最大值. 输入描述 输入3行5列共15个整数. 输出描述 输出每行的最大值.每个最大值占一行 #include<stdio.h>#include& ...

  10. outlook 2007 IMAP设置和配置

    以Outlook2007为例(Outlook2003操作基本类似).  1.依次点击“工具”>“帐户设置”. 2.在“帐户设置”页中点击“新建”> 不需要做任何选择,点击下一步. 3.填写 ...