locked
CRM 2011: JavaScript oData Function RRS feed

  • Question

  • Please take a look at the following few lines of code and see if you find anything wrong here.  

    I'm trying to create a JavaScript function to retrieve an entity I created for configuration settings.  In that entity I have created fields called dhi_value and dhi_key. In my other code such as plugins and web services, I am able to hit CRM and use the KEY to return the VALUE.  My entity is called dhi_adminconfiguration.

    The code runs but I continue to get an error that says that the entity or field is not found.  So I suspect my oData path is incorrect, probably the filter.  However, the names of the entity and fields are correct.  I suspect I've got something simply here that I a missing, as I have not tried hit CRM from JavaScript like this before, so I probably have some simple error that I cannot see.

    Any suggestions, thoughts, ideas, etc. are much appreciated.

    Best regards,

    Jon

    RetrieveAccount = function () {
    				
    		var oDataPath = Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc/dhi_adminconfiguration?$select=dhi_key,dhi_value&$filter=dhi_key eq 'CRM_WebService_Path'";		
    		alert(oDataPath);
    		var retrieveReq = new XMLHttpRequest();
    		retrieveReq.open("GET", oDataPath, false);
    		retrieveReq.setRequestHeader("Accept", "application/json");
    		retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    		retrieveReq.onreadystatechange = function () { retrieveReqCallBack(this); };
    		retrieveReq.send();
    	}
    
    	retrieveReqCallBack = function (retrieveReq) {
    		alert('callback:' + retrieveReq );
    		if (retrieveReq.readyState == 4 /* complete */) {
    			alert('ready');
    //            var retrieved = this.parent.JSON.parse(retrieveReq.responseText).d;
    //            alert(retrieved);
    //            var value = retrieved.results[0].dhi_value;
    //            alert(value);
    		 }
    	}


    Jon Gregory Rothlander

    Friday, December 5, 2014 3:15 PM

Answers

  • Just found the oData query tool.  It shows that I need to add "Set" to the end of my entity name.  Why is that? 

    Jon Gregory Rothlander

    Friday, December 5, 2014 3:42 PM

All replies

  • Just found the oData query tool.  It shows that I need to add "Set" to the end of my entity name.  Why is that? 

    Jon Gregory Rothlander

    Friday, December 5, 2014 3:42 PM
  • Hi Jon,

    Here you should refer the entity set.In your case it should be 'dhi_adminconfigurationSet'

    Refer this article :

    http://msdn.microsoft.com/en-us/library/gg334767.aspx

    It is good to generate the odata query from the oData query designer so that you can avoid the case sensitive issues.

    Thanks,

    Seban

    Friday, December 5, 2014 4:11 PM
  • Hello,

    You need to add "Set" after the entitname because it works with a collection, instead of a single entity record. For example, if you don't add anything in the $filter clause, you will get all the available records of the entitySet.

    Cornel


    Cornel Croitoriu - Senior Software Developer

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Biz-Forward.comCroitoriu.NET

    Thursday, December 18, 2014 11:16 AM