问题描述
基本问题。我正在XRM中使用Fetch XML Builder。如何告诉Fetch返回选项集标签而不是数字值?
我已经尝试了一切。我可以在结果集中看到OptionSet项的名称为“那里”:
retval
但是我在列视图中得到的实际结果是:
解决方法
在“结果”视图的左下角,单击“外观-友好名称”。
,我不确定您是否想知道如何在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#的方法,请对此发表评论。