0
votes

I am trying to get data from CRM 2011 through jQuery but I am unable to fetch the data. Here is my code:

function GetConfigurations() {

var oDataPath = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc";

    var filter = "/new_plugins_configurationSet?" +

  "$top=1";

var dataUrl=oDataPath + filter;
alert(dataUrl);

try
{
     $.ajax({url: dataUrl, success: function(result){
            alert(result);
        },error:function(error){console.log(error);alert("error");}});
}
catch(err)
{
    alert("error" + err.message);
}



}

This gives me the following error in the console of the CRM form:

enter image description here

Am I doing something wrong in the code?

Edited :

I have done changes in Js Code and now I am writing new_plugins_configurationset but it is returning Cross origin error even tough I am calling JS Code from CRM forms.

Here what I want to achieve is that on opening of one Entity CRM form, I want to read a second entity and put value in control of opening entity. that's why I am calling second entity using JS code.

2
Those aren't errors, they're warnings. The second one is because of your use of async: false which needs to be removed. I'd suggest you check the network tab of the console after making the request to see what the response code and text is. If the request is failing it should hopefully give you a useful error message you can debugRory McCrossan
hey @RoryMcCrossan I have removed async:false but still it won't able to call some how. is there any mistake in request?Imran Ahmad Shahid
@RoryMcCrossan I have one question that should we have to allow CORS in CRM to call organization service from javascript?Imran Ahmad Shahid
Within CRM form, CORS not at all needed for CRM service calls. Did you debug & see odataUri value?Arun Vinoth - MVP
@ArunVinoth I have checked the URl and here it is ServerAddress/OrganizationName/xrmservices/2011/…Imran Ahmad Shahid

2 Answers

1
votes

The issue is with dataset name, it should end with Set keyword. For your entity it should be new_plugins_configurationSet.

1
votes

I have resolved my problem. I was doing following mistakes through which I was unable to Get data from CRM.

  • The issue was with dataset name, it should end with Set keyword. For my entity it should be new_plugins_configurationSet.

  • I was using Xrm.Page.context.getServerUrl(); method to get serverUrl but by using this it's returning Cross origin error, so I used Xrm.Page.context.getClientUrl() to get complete server Url.