CRM FetchXML activitytypecode结果没有enum int值

问题描述 投票:3回答:1

我有一个JS项目,我想要提取CRM活动类型,让用户选择然后使用所选活动类型执行另一个fetchxml查询。

我可以使用简单的FetchXML获取不同的activitytypecode列表

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="activitypointer" >
<attribute name="activitytypecode" />
</entity>
</fetch>


result.attributes["activitytypecode"].formattedValue; //Returns name - 'Phone Call'

result.attributes["activitytypecode"].value; //Returns string - phonecall

我想要的是枚举的Int32值(例如:4210用于电话呼叫),例如,当我再次使用FetchXML进行查询时,我需要int32值。

我似乎无法从JavaScript中的FetchXML结果中获取它,但如果我使用XrmToolbox - 我可以看到int32值..我错过了什么?

formattedValue似乎=名称和值是文本表示而不是int32

enter image description here

这是该函数的完整代码:

function GetActivityTypes()
{
    var fetchXML = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">';
    fetchXML += '<entity name="activitypointer" >';
    fetchXML += '<attribute name="activitytypecode" />';
    fetchXML += '</entity>';
    fetchXML += '</fetch>';

    var results = XrmServiceToolkit.Soap.Fetch(fetchXML);

    if (results != null)    
    {
        for (index = 0; index < results.length; index++)
        {           
            var a = results[index].attributes["activitytypecode"].formattedValue; //returns activity type name - Phone Call

            var b = results[index].attributes["activitytypecode"].value;  //returns string - phonecall      
        }
    }       
}

我想要的只是活动类型的数值 - 即:电话= 4120

我正在使用最新的2.2.1版本的XrmServiceToolKit ..我也在里面打猎并注意到在'Fetch'方法中,随着结果的建立,它们被'反序列化'。

从Fetch方法的doRequest内部

var entity = new businessEntity();
entity.deserialize(fetchResult.childNodes[ii]);
fetchResults.push(entity);

我想知道是否有另一种方法可以在XrmServiceToolkit中使用...我甚至试图在我自己的FetchRAW方法中进行黑客攻击而不“反序列化”结果但是我对JS的确不够强大......我肯定一定是做错了。我已经成功地将Fetch方法用于其他实体数据,

javascript dynamics-crm dynamics-crm-2011 crm
1个回答
0
投票

您可以使用WebAPI(Odata)并在名称为Prefered的呼叫标题中包含odata.include-annotations = OData.Community.Display.V1.FormattedValue。

function retrieveEntity(entityName, Id, columnSet) {
    var serverURL = Xrm.Page.context.getClientUrl();
    var Query = entityName + "(" + Id + ")" + columnSet;
    var req = new XMLHttpRequest();
    req.open("GET", serverURL + "/api/data/v8.0/" + Query, true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");
    req.onreadystatechange = function() {
        if (this.readyState == 4 /* complete */ ) {
            req.onreadystatechange = null;
            if (this.status == 200) {
                var data = JSON.parse(this.response);
                if (data != null {
                        alert(data["_primarycontactid_value@OData.Community.Display.V1.FormattedValue"]); //for lookup text
                        alert(data["[email protected]"]); //for optionset text
                    }
                } else {
                    var error = JSON.parse(this.response).error;
                    alert(error.message);
                }
            }
        };
        req.send();
    }

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/query-data-web-api#include-formatted-values

http://himbap.com/blog/?p=2077

希望它有所帮助 - M.Acosta.D

© www.soinside.com 2019 - 2024. All rights reserved.