Dynamics CRM Web资源未知错误

时间:2016-05-12 15:00:15

标签: javascript dynamics-crm

我正在为我正在使用的表单创建扩展程序。

这是JS代码(这是我第一次参加js,我根本不是专家)。

LookupFieldObject = Xrm.Page.data.entity.attributes.get('new_richiesta');
//new_richiesta is a field in my modul, it has the ref to the Incident
    if (LookupFieldObject.getValue() != null) {
        var id = LookupFieldObject.getValue()[0].id; 

        var serverUrl = Xrm.Page.context.getClientUrl().toString();
        var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
        var crmEntity = new Object();
        var ODATA_EntityCollection = "/IncidentSet(guid'" + id + "')"; //this code was wrong, now it's ok 
        // IncidentSet is my dataSet

        var jsonEntity = window.JSON.stringify(crmEntity);

        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: false,
            url: serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection,

            beforeSend: function (XMLHttpRequest) {
                //XMLHttpRequest.setRequestHeader("Accept", "application/json");

                //XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
            },
            success: function (data, textStatus, XmlHttpRequest) {
                if (data && data.d) {
                    GetPlantInfo(data.d);
                }
            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
                }
        });
      }
}
//[... other functions similar to this ...]

我删除了其他代码,因为我只尝试了这个(并且空方法调用成功),我收到了错误。

此代码有什么问题?

PS: 错误是空的,我得到Error:unknown

修改

function addFilter(res) //res is an array of objects (the result of my querying)
{
    var mystring= "<filter type='and'><filter type='or'>"; //here I prepare a string for the filter creation

    for (var i = 0; i < res.results.length; i++){//I cycle all results and I create the filter
        var lettura = res.results[i];
        mystring+= "<condition attribute='new_meterreadingtypeid' operator='eq' uiname='";
        mystring+= lettura.new_name.replace(/\'/g,"''"); //this is because some names contain a `'`.
        mystring+= "' uitype='new_meterreadingtype' value='{";
        mystring+= lettura.new_tipoletturatipoimpiantoId.toString();
        mystring+= "}' />";
     }

     mystring+= "</filter></filter>";
     try{ //here I have my filter, and it looks like the code I post below
        Xrm.Page.getControl("new_tipologialettura").addCustomFilter(mystring); //the code succed here and I have no errors. 
     //new_tipologialettura is the name of my module's property
     } catch(e){
        throw new Error(e.Message);
     }
}

这就是我的过滤器的样子:

<filter type='and'>
    <filter type='or'>
        <condition attribute='new_meterreadingtypeid' operator='eq' uiname='DEPURAZIONE / ASD123123123 AAAAAA' uitype='new_meterreadingtype' value='{bf119b99-94b6-499a-ad91-2a9dde0d8f5c}' />
        <condition attribute='new_meterreadingtypeid' operator='eq' uiname='DEPURAZIONE / Lettura contatore mobile' uitype='new_meterreadingtype' value='{6ac386c1-949c-4817-b2e5-800221d35224}' />
        <condition attribute='new_meterreadingtypeid' operator='eq' uiname='DEPURAZIONE / By-pass - Max 10 Scelte  e i caratteri ''@'' e ''&'' sono vietati' uitype='new_meterreadingtype' value='{9eaee542-7764-4949-a117-f5bb2c9b7040}' />
    </filter>
</filter>

我不明白为什么一切都没有任何错误,但我仍然无法过滤我的领域。我错过了什么?

0 个答案:

没有答案