Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Microsoft Dynamics Online:将所有选项集项复制到多行文本字段(使用JavaScript)_Javascript_Dynamics Crm 2011_Dynamics Crm - Fatal编程技术网

Microsoft Dynamics Online:将所有选项集项复制到多行文本字段(使用JavaScript)

Microsoft Dynamics Online:将所有选项集项复制到多行文本字段(使用JavaScript),javascript,dynamics-crm-2011,dynamics-crm,Javascript,Dynamics Crm 2011,Dynamics Crm,我有一个表单,有两个自定义字段:“选项集”和“多行文本”。我将JavaScript文件作为WebResource上传,并将该函数添加到表单的Onload事件中。 我想知道如何使用JavaScript将所有选项集项复制到多行文本框 尝试使用此代码段:此请求获取选项集的元数据,并以XML形式从CRM返回所有数据 if (typeof (SDK) == "undefined") { SDK = { __namespace: true }; } //This will establish a

我有一个表单,有两个自定义字段:“选项集”和“多行文本”。我将JavaScript文件作为WebResource上传,并将该函数添加到表单的Onload事件中。
我想知道如何使用JavaScript将所有选项集项复制到多行文本框

尝试使用此代码段:此请求获取选项集的元数据,并以XML形式从CRM返回所有数据

if (typeof (SDK) == "undefined")   { SDK = { __namespace: true }; }
   //This will establish a more unique namespace for functions in this library. This will reduce the 
   // potential for functions to be overwritten due to a duplicate name when the library is loaded.
   SDK.OptionSet = {
       _getServerUrl: function () {
           ///<summary>
           /// Returns the URL for the SOAP endpoint using the context information available in the form
           /// or HTML Web resource.
           ///</summary>
           var ServicePath = "/XRMServices/2011/Organization.svc/web";
           var serverUrl = "";
           if (typeof GetGlobalContext == "function") {
               var context = GetGlobalContext();
               serverUrl = context.getServerUrl();
           }
           else {
               if (typeof Xrm.Page.context == "object") {
                     serverUrl = Xrm.Page.context.getServerUrl();
               }
               else
               { throw new Error("Unable to access the server URL"); }
               }
              if (serverUrl.match(/\/$/)) {
                   serverUrl = serverUrl.substring(0, serverUrl.length - 1);
               } 
               return serverUrl + ServicePath;
           }, 
       GetOptionSetValuesRequest: function () {
           var requestMain = ""
           requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
           requestMain += "  <s:Body>";
           requestMain += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
           requestMain += "      <request i:type=\"a:RetrieveAttributeRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
           requestMain += "        <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
           requestMain += "          <a:KeyValuePairOfstringanyType>";
           requestMain += "            <b:key>MetadataId</b:key>";
           requestMain += "            <b:value i:type=\"c:guid\" xmlns:c=\"http://schemas.microsoft.com/2003/10/Serialization/\">00000000-0000-0000-0000-000000000000</b:value>";
           requestMain += "          </a:KeyValuePairOfstringanyType>";
           requestMain += "          <a:KeyValuePairOfstringanyType>";
           requestMain += "            <b:key>RetrieveAsIfPublished</b:key>";
           requestMain += "            <b:value i:type=\"c:boolean\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">true</b:value>";
           requestMain += "          </a:KeyValuePairOfstringanyType>";
           requestMain += "          <a:KeyValuePairOfstringanyType>";
           requestMain += "            <b:key>EntityLogicalName</b:key>";
           requestMain += "            <b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">"+ENTITYLOGICALNAME+"</b:value>";
           requestMain += "          </a:KeyValuePairOfstringanyType>";
           requestMain += "          <a:KeyValuePairOfstringanyType>";
           requestMain += "            <b:key>LogicalName</b:key>";
           requestMain += "            <b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">"+ATTRIBUTENAME+"</b:value>";
           requestMain += "          </a:KeyValuePairOfstringanyType>";
           requestMain += "        </a:Parameters>";
           requestMain += "        <a:RequestId i:nil=\"true\" />";
           requestMain += "        <a:RequestName>RetrieveAttribute</a:RequestName>";
           requestMain += "      </request>";
           requestMain += "    </Execute>";
           requestMain += "  </s:Body>";
           requestMain += "</s:Envelope>";
           var req = new XMLHttpRequest();
           req.open("POST", SDK.OptionSet._getServerUrl(), false)
           req.setRequestHeader("Accept", "application/xml, text/xml, */*");
           req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
           req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
           req.send(requestMain);
           //work with the response here
           var strResponse = req.responseXML.xml;
           //alert(strResponse.toString());
       }, __namespace: true};
if(typeof(SDK)=“未定义”){SDK={{uuu名称空间:true};}
//这将为此库中的函数建立一个更独特的命名空间。这将降低成本
//加载库时,可能由于名称重复而覆盖函数。
SDK.OptionSet={
_getServerUrl:函数(){
///
///使用表单中可用的上下文信息返回SOAP端点的URL
///或HTML网页资源。
///
var ServicePath=“/XRMServices/2011/Organization.svc/web”;
var serverUrl=“”;
if(GetGlobalContext的类型==“函数”){
var context=GetGlobalContext();
serverUrl=context.getServerUrl();
}
否则{
if(typeof Xrm.Page.context==“对象”){
serverUrl=Xrm.Page.context.getServerUrl();
}
其他的
{抛出新错误(“无法访问服务器URL”);}
}
if(serverUrl.match(/\/$/)){
serverUrl=serverUrl.substring(0,serverUrl.length-1);
} 
返回serverUrl+ServicePath;
}, 
GetOptionSetValuesRequest:函数(){
var requestMain=“”
requestMain+=“”;
requestMain+=“”;
requestMain+=“”;
requestMain+=“”;
requestMain+=“”;
requestMain+=“”;
requestMain+=“MetadataId”;
requestMain+=“00000000-0000-0000-0000-000000000000”;
requestMain+=“”;
requestMain+=“”;
requestMain+=“RetrieveAsIfPublished”;
requestMain+=“true”;
requestMain+=“”;
requestMain+=“”;
requestMain+=“EntityLogicalName”;
requestMain+=“”+ENTITYLOGICALNAME+“”;
requestMain+=“”;
requestMain+=“”;
requestMain+=“LogicalName”;
requestMain+=“”+ATTRIBUTENAME+“”;
requestMain+=“”;
requestMain+=“”;
requestMain+=“”;
requestMain+=“RetrieveAttribute”;
requestMain+=“”;
requestMain+=“”;
requestMain+=“”;
requestMain+=“”;
var req=新的XMLHttpRequest();
请求打开(“POST”,SDK.OptionSet.\u getServerUrl(),false)
setRequestHeader(“接受”、“应用程序/xml、文本/xml、*/*”);
请求setRequestHeader(“内容类型”,“文本/xml;字符集=utf-8”);
请求setRequestHeader(“SOAPAction”http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
请求发送(requestMain);
//在这里使用响应
var strResponse=req.responseXML.xml;
//警报(strResponse.toString());
},_名称空间:true};
响应将是strResponse。您将需要解析它。这是一个相当大的响应,所以我只提供其中的一部分:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
          <s:Body>
            <ExecuteResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
              <ExecuteResult i:type="a:RetrieveAttributeResponse" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
                <a:ResponseName>RetrieveAttribute</a:ResponseName>
                <a:Results xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
                  <a:KeyValuePairOfstringanyType>
                    <b:key>AttributeMetadata</b:key>
                    <b:value i:type="c:PicklistAttributeMetadata" xmlns:c="http://schemas.microsoft.com/xrm/2011/Metadata">
<!-- a lots of data -->
               <c:OptionSet>
                <c:MetadataId>761cd65c-1d0f-e311-bb04-d48564519ccb</c:MetadataId>
                <c:HasChanged i:nil="true" />
                <c:Description>
                  <a:LocalizedLabels />
                  <a:UserLocalizedLabel i:nil="true" />
                </c:Description>
                <c:DisplayName>
                  <a:LocalizedLabels>
                    <a:LocalizedLabel>
                      <c:MetadataId i:nil="true" />
                      <c:HasChanged i:nil="true" />
                      <a:IsManaged>false</a:IsManaged>
                      <a:Label>Previous Supplier</a:Label>
                      <a:LanguageCode>1033</a:LanguageCode>
                    </a:LocalizedLabel>
                  </a:LocalizedLabels>
                  <a:UserLocalizedLabel>
                    <c:MetadataId i:nil="true" />
                    <c:HasChanged i:nil="true" />
                    <a:IsManaged>false</a:IsManaged>
                    <a:Label>Previous Supplier</a:Label>
                    <a:LanguageCode>1033</a:LanguageCode>
                  </a:UserLocalizedLabel>
                </c:DisplayName>
                <c:IsCustomOptionSet>true</c:IsCustomOptionSet>
                <c:IsCustomizable>
                  <a:CanBeChanged>true</a:CanBeChanged>
                  <a:ManagedPropertyLogicalName>iscustomizable</a:ManagedPropertyLogicalName>
                  <a:Value>true</a:Value>
                </c:IsCustomizable>
                <c:IsGlobal>false</c:IsGlobal>
                <c:IsManaged>false</c:IsManaged>
                <c:Name>ut_budgetconrtroller_ut_previoussupplier</c:Name>
                <c:OptionSetType>Picklist</c:OptionSetType>
                <c:Options>
                  <c:OptionMetadata>
                    <c:MetadataId i:nil="true" />
                    <c:HasChanged i:nil="true" />
                    <c:Description>
                      <a:LocalizedLabels />
                      <a:UserLocalizedLabel i:nil="true" />
                    </c:Description>
                    <c:IsManaged>false</c:IsManaged>
                    <c:Label>
                      <a:LocalizedLabels>
                        <a:LocalizedLabel>
                          <c:MetadataId i:nil="true" />
                          <c:HasChanged i:nil="true" />
                          <a:IsManaged>false</a:IsManaged>
                          <a:Label>Option 0</a:Label>
                          <a:LanguageCode>1033</a:LanguageCode>
                        </a:LocalizedLabel>
                      </a:LocalizedLabels>
                      <a:UserLocalizedLabel>
                        <c:MetadataId i:nil="true" />
                        <c:HasChanged i:nil="true" />
                        <a:IsManaged>false</a:IsManaged>
                        <a:Label>Option 0</a:Label>
                        <a:LanguageCode>1033</a:LanguageCode>
                      </a:UserLocalizedLabel>
                    </c:Label>
                    <c:Value>206350001</c:Value>
                  </c:OptionMetadata>
                  <c:OptionMetadata>
                    <c:MetadataId i:nil="true" />
                    <c:HasChanged i:nil="true" />
                    <c:Description>
                      <a:LocalizedLabels />
                      <a:UserLocalizedLabel i:nil="true" />
                    </c:Description>
                    <c:IsManaged>false</c:IsManaged>
                    <c:Label>
                      <a:LocalizedLabels>
                        <a:LocalizedLabel>
                          <c:MetadataId i:nil="true" />
                          <c:HasChanged i:nil="true" />
                          <a:IsManaged>false</a:IsManaged>
                          <a:Label>Option 1</a:Label>
                          <a:LanguageCode>1033</a:LanguageCode>
                        </a:LocalizedLabel>
                      </a:LocalizedLabels>
                      <a:UserLocalizedLabel>
                        <c:MetadataId i:nil="true" />
                        <c:HasChanged i:nil="true" />
                        <a:IsManaged>false</a:IsManaged>
                        <a:Label>Option 1</a:Label>
                        <a:LanguageCode>1033</a:LanguageCode>
                      </a:UserLocalizedLabel>
                    </c:Label>
                    <c:Value>206350002</c:Value>
                  </c:OptionMetadata>                  
                </c:Options>
              </c:OptionSet>
            </b:value>
          </a:KeyValuePairOfstringanyType>
        </a:Results>
      </ExecuteResult>
    </ExecuteResponse>
  </s:Body>
</s:Envelope>

检索属性
属性元数据
761cd65c-1d0f-e311-bb04-d48564519ccb
假的
前供应商
1033
假的
前供应商
1033
真的
真的
不可定制
真的
假的
假的
ut\u预算管理员\u ut\u以前的供应商
挑选名单
假的
假的
选项0
1033
假的
选项0
1033
206350001
假的
假的
选择1
1033