【问题标题】:Fetch XML and optionSets获取 XML 和选项集
【发布时间】:2020-12-22 04:42:07
【问题描述】:

基本问题。我在 XRM 中使用 Fetch XML 构建器。如何告诉 Fetch 返回选项集标签而不是数值?

我什么都试过了。我可以在结果集中看到 OptionSet 项的名称是“there”:

<resultset morerecords="0" >
  <result>
    <est formattedvalue="4,337.50" >4337.5</est>
    <sector name="Sustainable Industrial" formattedvalue="100000000" >100000000</sector>
    <sector_new_nsectorname>Sustainable Industrial</sector_new_nsectorname>
  </result>
  <result>
    <est formattedvalue="3,216.00" >3216</est>
    <sector name="Renewable" formattedvalue="100000002" >100000002</sector>
    <sector_new_nsectorname>Renewable</sector_new_nsectorname>
  </result>
  <result>
    <est formattedvalue="2,329.25" >2329.25</est>
    <sector name="Environmental" formattedvalue="100000001" >100000001</sector>
    <sector_new_nsectorname>Environmental</sector_new_nsectorname>
  </result>
</resultset>

但我在列视图中得到的实际结果是:

【问题讨论】:

    标签: dynamics-365 fetchxml


    【解决方案1】:

    在结果视图的左下角,单击外观 - 友好名称。

    【讨论】:

    【解决方案2】:

    我不确定您是想知道如何在 FetchXrmBuilder 中显示 OptionSet 标签,还是在代码中使用 fetchXML 实际获取标签的值。

    很遗憾,您无法通过操作获取来获取标签值。我正在添加一个示例 JS 代码,通过向 stringmap 实体发出另一个获取请求来获取 OptionSet 的标签值。我使用 product(Entity) 和 producttypecode(OptionSet) 来显示如何通过操纵 2 个不同 fetch 的结果集在单个结果集中获取相应的标签值。

    var finalProductList = [];
    var optionSetValueDict = {};
    var productResultSet = [];
    
    function OnLoad(executionContext)
    {
        RetrieveOptionSetValue();
        RetrieveProduct();
    }
    
    function CreateOptionSetDict(optionSetValueResultSet)
    {
        optionSetValueResultSet.forEach(function (obj)
        {
            optionSetValueDict[obj.attributevalue] = obj.value;
        });
    }
    
    function CreateProductList(productResultSet)
    {
        productResultSet.forEach(function (obj)
        {
            var finalProduct = {};
            finalProduct['producttypecode'] = obj.producttypecode;
            finalProduct['producttypecodevalue'] = optionSetValueDict[obj.producttypecode];
            finalProduct['productnumber'] = obj.productnumber;
            finalProductList.push(finalProduct);
        });
    }
    
    function RetrieveProduct()
    {
        var results;
        var fetchXmlQuery = '<fetch top="50" ><entity name="product" ><attribute name="productnumber" /><attribute name="producttypecode" /></entity></fetch>';
        var req = new XMLHttpRequest();
        req.open(
            "GET",
        Xrm.Page.context.getClientUrl() +
            "/api/data/v9.0/products?fetchXml=" + encodeURIComponent(fetchXmlQuery),
        false);
        req.setRequestHeader("Prefer", 'odata.include-annotations="*"');
        req.onreadystatechange = function ()
        {
            if (this.readyState === 4)
            {
                req.onreadystatechange = null;
                if (this.status === 200)
                {
                    var results = JSON.parse(this.response);
                    CreateProductList(results.value);
                }
                else
                {
                    alert(this.statusText);
                }
            }
        };
        req.send();
    }
    
    function RetrieveOptionSetValue()
    {
        var fetchXmlQuery = '<fetch><entity name="stringmap" ><attribute name="attributevalue" /><attribute name="value" /><filter type="and" ><condition attribute="objecttypecodename" operator="eq" value="product" /><condition attribute="attributename" operator="eq" value="producttypecode" /></filter></entity></fetch>';
        var req = new XMLHttpRequest();
        req.open(
            "GET",
        Xrm.Page.context.getClientUrl() +
            "/api/data/v9.0/stringmaps?fetchXml=" + encodeURIComponent(fetchXmlQuery),
        false);
        req.setRequestHeader("Prefer", 'odata.include-annotations="*"');
        req.onreadystatechange = function ()
        {
            if (this.readyState === 4)
            {
                req.onreadystatechange = null;
                if (this.status === 200)
                {
                    var results = JSON.parse(this.response);
                    CreateOptionSetDict(results.value);
                }
                else
                {
                    alert(this.statusText);
                }
            }
        };
        req.send();
    }
    

    希望对您有所帮助。如果您正在 C# 中寻找解决方法,请发表评论。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-18
      • 2020-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多