微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

获取XML和optionSet

如何解决获取XML和optionSet

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

我已经尝试了一切。我可以在结果集中看到OptionSet项的名称为“那里”:

retval

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

enter image description here

解决方法

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

Screenshot of FetchXML Builder

,

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

不幸的是,您无法通过操纵提取来获取标签值。我正在添加示例JS代码,以通过对stringmap实体进行另一个提取请求来获取OptionSet的标签值。我已经使用product(Entity)和producttypecode(OptionSet)来显示如何通过操纵2个不同的访存结果集来在单个结果集中获取相应的标签值。

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),'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#的方法,请对此发表评论。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?