Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error while creating custom entity using javascript

(0) ShareShare
ReportReport
Posted on by

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
    34,477 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
    84,331 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
    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
    84,331 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
    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
    84,331 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
    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
    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
    84,331 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
    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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
dkrishna Profile Picture

dkrishna 6

Featured topics

Product updates

Dynamics 365 release plans