web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

WebAPI : Unable to access custom entity using Web API.

(0) ShareShare
ReportReport
Posted on by 337

I am struck here badly, Have been trying different options but no use.

I have two entities and have to create an association between these two.

I have the following code to achieve this.

 var clientURL = parent.Xrm.Page.context.getClientUrl();  
    var req = new XMLHttpRequest()    
    req.open("POST", encodeURI(clientURL + "/api/data/v8.0/new_experiencetopgs"), true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.onreadystatechange = function () {
        if (this.readyState == 4 /* complete */) {
            req.onreadystatechange = null;
            if (this.status == 204) {
                var accountUri = this.getResponseHeader("OData-EntityId");                
            }
            else {
                var error = JSON.parse(this.response).error;
            }
        }
    };
    var experiencetopgs = new Object();
    //String Field
    experiencetopgs.new_name = Math.random()+"ExperienceGroup";
    var experienceId =parent.Xrm.Page.data.entity.getId().substring(1, 37);
    //Lookup
	
    experiencetopgs["new_exppgexperience@odata.bind"] = "/***_experiences("+experienceId+")"
	experiencetopgs["new_exppracticegroup@odata.bind"] = "/new_experiencetopgs("+practiceGroupId+")"
	jObj=JSON.stringify(experiencetopgs).replace(/ /g,'');
    var response = req.send(jObj);


When it comes to ***_experiences, it's not accessible, I tried to directly access this entity using web API URL.

server/.../v8.0***_experienceses

Response : 

{
  "error":{
    "code":"","message":"Resource not found for the segment '***_experienceses'.",
"innererror":{ "message":"Resource not found for the segment '***_experienceses'.",
"type":"Microsoft.OData.Core.UriParser.ODataUnrecognizedPathException",
"stacktrace":"at Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.ParsePath(ICollection`1 segments)\r\n at Microsoft.OData.Core.UriParser.Parsers.ODataPathFactory.BindPath(ICollection`1 segments, ODataUriParserConfiguration configuration)\r\n at Microsoft.OData.Core.UriParser.ODataUriParser.Initialize()\r\n at System.Web.OData.Routing.DefaultODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath, ODataUriResolverSetttings resolverSettings, Boolean enableUriTemplateParsing)\r\n at System.Web.OData.Routing.DefaultODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath)" } } }

*This post is locked for comments

I have the same question (0)
  • Prashanth Kamasamudram Profile Picture
    337 on at

    I have also tried to install metadata browser and check for entity name and schema names, Everything is correct and also tried using the plural name. nothing is working.

    IS there any chance of some metadata setting for an entity which is blocking wep api from accessing this entity?

  • Verified answer
    Thomas David Dayman Profile Picture
    11,323 on at

    I know you stated that you checked the schema names. Are they in the correct case as I think its case sensitive.

    Or you could use the CRM REST Builder to generate the code for you: github.com/.../CRMRESTBuilder

  • Verified answer
    ashlega Profile Picture
    34,477 on at

    Hi,

      did you try to see your custom entity "set" name in the XrmToolBox Metadata Browser?

    2450.1.PNG

      I believe that's the name you should be using, so it might be different somehow

  • Prashanth Kamasamudram Profile Picture
    337 on at

    Thank you for ur response, I did import this solution and generated the code.

    Following is the code which got generated.

    var entity = {};
    
    entity["new_exppgexperience@odata.bind"] = "/null()";
    
    entity["new_exppracticegroup@odata.bind"] = "/new_practicegroups()";
    
    entity.new_name = "";
    
    $.ajax({
    
       type: "POST",
    
       contentType: "application/json; charset=utf-8",
    
       datatype: "json",
    
       url: Xrm.Page.context.getClientUrl() + "/api/data/v8.0/new_experiencetopgs",
    
       data: JSON.stringify(entity),
    
       beforeSend: function(XMLHttpRequest) {
    
           XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
    
           XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
    
           XMLHttpRequest.setRequestHeader("Accept", "application/json");
    
           XMLHttpRequest.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    
       },
    
       async: false,
    
       success: function(data, textStatus, xhr) {
    
           var uri = xhr.getResponseHeader("OData-EntityId");
    
           var regExp = /\(([^)]+)\)/;
    
           var matches = regExp.exec(uri);
    
           var newEntityId = matches[1];
    
       },
    
       error: function(xhr, textStatus, errorThrown) {
    
           Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
    
       }
    
    });


    If you see at the third line of code, we got null in place of the entity name.

    entity["new_exppgexperience@odata.bind"] = "/null()";

    the entity is there and is being used but is not accessible by external code it seems.

  • Prashanth Kamasamudram Profile Picture
    337 on at

    Hi Alex,

       Checked it, its showing null.

    Kind Regards

    Prashanth

  • Prashanth Kamasamudram Profile Picture
    337 on at

    Hi Alex,

    It seems like this is the reason Web API is unable to find the reference to Entity.

    Is there any way to update this and give proper name?

    Kind Regards

    Prashanth

  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    Hi Prashanth,

     I did not try it, but maybe this would work:

    - Add that entity to a new solution

    - Export your solution

    - Open customizaitons.xml

    - Find <EntitySetName> tag

    - Add your plural name there

    - Repackage and import back to CRM

     If, somehow, you can't find EntitySetName tag at all, it follow "attributes/>" in my case, so try adding it then:

             </attributes>  

             <EntitySetName>tcs_lookupconfigs</EntitySetName>

             <IsDuplicateCheckSupported>0</IsDuplicateCheckSupported>

    PS. I was sure I saw this link just the other day.. could not find it right away - some useful reading there, too:

    community.dynamics.com/.../crm-2016-web-api-and-plural-names

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Prashanth,

    Try using the following URL.

    url: Xrm.Page.context.getClientUrl() + "/api/data/v8.0/new_experiencetopges"

    Try using the plural name of the entity.

    Can you share a screenshot of the custom entity information? 

  • CrmMad Profile Picture
    65 on at

    Hello prashanth.kamasamudram,

    I had the same error.

    I resolved the problem open the metada with XRMtoolbox and there I can my setentityname was "why_pricingruleses" instead "why_pricingrules". I don't know why the system save the plural name instead singular name

    I resolved the problem with this

    Best Regards

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans