crm 2011 IFD无法使用OData和Javascript

时间:2014-04-02 09:57:59

标签: javascript dynamics-crm-2011 odata

首先,我们的crm 2011是内部部署。然后改为IFD(https://myservername.mycompany.com/ORGName/XRMServices/2011/Organization.svc)。当更改为IFD时,所有OData和javascript都无法正常工作。

内部部署中,我们使用服务器网址...
var lvSz_CRMServerURL = Xrm.Page.Context.getServerUrl(); 它适用于OData和JS。

IFD 中,我们使用服务器网址..

var lvSz_CRMODataSvcURLEndpoint = Xrm.Page.context.prependOrgName (" /XRMServices/2011/OrganizationData.svc"); Odata和JS功能不起作用,无法访问。

当使用prependOrgName和lvObj_XMLDocHnd2.open(" GET",lvSz_ODataQueryURL, true )时, lvObj_XMLDocHnd2.readyState 1 。(应该是4)

当使用prependOrgName和lvObj_XMLDocHnd2.open(" GET",lvSz_ODataQueryURL, false )时, lvObj_XMLDocHnd2.readyState 4 lvObj_XMLDocHnd2.status 404 (应为200)。所以OData和JS被停止了,不经过检查。

请给我任何建议。可能是配置或JS功能有什么问题。

请查看我的OData和JS功能

.....

function JS_GenerateQuotation() {
//debugger;
var opportunityId = Xrm.Page.data.entity.getId(); //Xrm.Page.getAttribute("new_opportunityid").getValue()[0].id;
var prepareQuotation;

//var lvSz_CRMServerURL = rootURL + "/GBGroupUAT"; 
//var lvSz_CRMODataSvcURLEndpoint = lvSz_CRMServerURL + "/XRMServices/2011/OrganizationData.svc";

var lvSz_CRMODataSvcURLEndpoint = Xrm.Page.context.prependOrgName("/XRMServices/2011/OrganizationData.svc");

var lvObj_XMLDocHnd2 = null;
lvObj_XMLDocHnd2 = new XMLHttpRequest();

var relatedEntity = "opportunity";
var lvSz_ODataQueryURL = lvSz_CRMODataSvcURLEndpoint + ((relatedEntity == "opportunity") ? "/OpportunitySet?$select=new_PrepareQuotation&$filter=OpportunityId eq guid'" + opportunityId + "'" : "");

lvObj_XMLDocHnd2.open("GET", lvSz_ODataQueryURL, false);
lvObj_XMLDocHnd2.setRequestHeader("Accept", "application/json");
lvObj_XMLDocHnd2.setRequestHeader("Content-Type", "application/json; charset=utf-8");
var lvArr_CRMRecordsMatchingSpecifiedGUID;

lvObj_XMLDocHnd2.onreadystatechange = function () {
    if (lvObj_XMLDocHnd2.readyState == 4) {
        if (lvObj_XMLDocHnd2.status == 200) {

            lvArr_CRMRecordsMatchingSpecifiedGUID = eval('(' + lvObj_XMLDocHnd2.responseText + ')');

            if (lvArr_CRMRecordsMatchingSpecifiedGUID == null || lvArr_CRMRecordsMatchingSpecifiedGUID == "" || lvArr_CRMRecordsMatchingSpecifiedGUID.d.results[0] == null) {

            }
            else {
                prepareQuotation = lvArr_CRMRecordsMatchingSpecifiedGUID.d.results[0].new_PrepareQuotation;
            }
        }
    }
}
lvObj_XMLDocHnd2.send();

if (prepareQuotation != false) {
    var GUIDvalue = Xrm.Page.data.entity.getId();

    var serverUrl = urlGenerateQuotation + GUIDvalue;

    var features = "location=no,menubar=no,status=no,toolbar=no,resizable=1";
    window.open(serverUrl, "_blank", features);
}
else {
    alert("Please prepare quotation.");
}

}

1 个答案:

答案 0 :(得分:0)

IFD OData端点应如下所示:https://orgname.domain/XRMServices/2011/OrganizationData.svc

您可以在设置 - >下阅读正确的网址自定义 - > 开发人员资源

从UR12开始,您应该使用Xrm.Page.context.getClientUrl()取代Xrm.Page.context.getServerUrl()来获取该组织的基本网址。