Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Error while creating custom entity using javascript

Posted on by Microsoft Employee

Here is my error

{
"error":{
"code":"","message":"Resource not found for the segment 'testacc'.","innererror":{
"message":"Resource not found for the segment 'testacc'.","type":"Microsoft.OData.Core.UriParser.ODataUnrecognizedPathException","stacktrace":" at Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.CreateFirstSegment(String segmentText)\r\n 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 Microsoft.OData.Core.UriParser.ODataUriParser.ParsePath()\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

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Error while creating custom entity using javascript

    Hi Shivam,

     get that link, post it to the browser, and see if anything shows up. Once you see some data, you can be sure it's the right link (and, then, you can use it for "post")

     But, to the Andrew's point.. you should be using plural name, which is, likely, new_testaccs (not new_testacc)

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Error while creating custom entity using javascript

    My suggestions are following:

    1. Include  reference to GlobalContext of page - msdn.microsoft.com/.../gg328541.aspx

    2. Try to use following code:

    function CreateEntity(clientUrl,entityType,entityData)

    {

      debugger;

      alert('Inside Method');

      var req = new XMLHttpRequest()

      req.open("POST", encodeURI(clientUrl + "/api/data/v8.1/" + entityType) , 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 */) {

              alert("hi");

              req.onreadystatechange = null;

              alert(this.status);

              if (this.status == 204) {

                  var accountUri = this.getResponseHeader("OData-EntityId");

                  alert(accountUri);

                  console.log("Created " + entityType + " with URI " + accountUri);

              }

              else {

                  var error = JSON.parse(this.response).error;

                  alert(error);

                  console.log(error.message);

              }

          }

      };

      req.send(JSON.stringify(entityData));

    }

    in index.cshtml file

    <script>

      $(document).ready(function ()

      {

          alert('On Page');

          var clientUrl = GetGlobalContext().getClientUrl();

          var entityType = "new_testaccs";

          var entityData = { "new_name": "bnkac" , "new_phone": "787897" };

          CreateEntity(clientUrl, entityType, entityData);

      });

    </script>

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error while creating custom entity using javascript

    1.Yes basically it is html+angular js web resource in crm from there on click of button values provided in form and create a custom entity in crm .

    2. But my primary aim is to first create custom Entity on Dynamic CRM using microsoft web api.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Error while creating custom entity using javascript

    What do you develop? Is it html-webresource for CRM?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error while creating custom entity using javascript

    I want to create custom Entity on Dynamic CRM using microsoft web api .So how to call api using jquery and what  request header and required parameters will be added for that.We have tried several times through sent code but did not get any luck.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Error while creating custom entity using javascript

    What do you develop? Is it html webresource for CRM?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error while creating custom entity using javascript

    while using this method

    CreateEntity(Xrm.Page.context.getClientUrl(), "custom entity name in plural here", RecordToCreateHere);

    it will not enter into the function . May be in my understanding it is not understanding XRM thats why not enter into function.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error while creating custom entity using javascript

    function CreateEntity(clientUrl,entityType,entityData)

    {

       debugger;

       alert('Inside Method');

       var req = new XMLHttpRequest()

       req.open("POST", encodeURI(clientUrl + "/api/data/v8.1/" + entityType) , 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 */) {

               alert("hi");

               req.onreadystatechange = null;

               alert(this.status);

               if (this.status == 204) {

                   var accountUri = this.getResponseHeader("OData-EntityId");

                   alert(accountUri);

                   console.log("Created " + entityType + " with URI " + accountUri);

               }

               else {

                   var error = JSON.parse(this.response).error;

                   alert(error);

                   console.log(error.message);

               }

           }

       };

       req.send(JSON.stringify(entityData));

    }

    in index.cshtml file

    <script>

       $(document).ready(function ()

       {

           alert('On Page');

           var clientUrl = "https://stiertrial.api.crm8.dynamics.com;

           var entityType = "new_testacc";

           var entityData = { "new_name": "bnkac" , "new_phone": "787897" };

           CreateEntity(clientUrl, entityType, entityData);

       });

    </script>

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Error while creating custom entity using javascript

    Can you please post full version of your modified code?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error while creating custom entity using javascript

    Hi Andrew  

    thanks for your help .

    But in my code when i check status in my  code

    alert(this.status);

    it returns 0 and code stop after that.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans