如何在动力学crm中使用Odata获取状态代码?

时间:2014-07-17 07:20:57

标签: dynamics-crm-2011 odata dynamics-crm dynamics-crm-4 dynamics-crm-2013

使用Odata查询我正在获取CRM字段。但是statuscode的类型为OptionSet,你如何得到statuscode。我尝试了下面的代码,它无法获得0或未定义。你有什么参考赞赏的吗?

$.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: odata_point + "(guid'" + x + "')",
        beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
        success: function (data, textStatus, XmlHttpRequest) {
            RetrieveEntityData(data.d);
            alert(data.d.Name);
            alert(data.d[0].StatusCode.Value); //here i'm getting Unable to get 0 or undefined.
       }

1 个答案:

答案 0 :(得分:2)

var retrievedLeadState = data.d.results[0].StateCode;

// StateCode is an OptionSet so we must use eval-function
var stateCode = eval(retrievedLeadState.Value);

alert(stateCode);

参考:CRM 2011: Retrieve StateCode (Status) using oData (REST) Service Endpoint