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

Announcements

News and Announcements icon
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

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    if you are trying to create a new record of a custom entity, I would suggest you to use the RestBuilder (juste import the managed solution and open it) github.com/.../CRMRESTBuilder

    Best

  • Suggested answer
    Subramanya Profile Picture
    165 on at

    Hi Shivam,

    Please check your entity schema name in your request.

    You have to mention complete schema name of the entity like "new_testacc" if your publisher prefix is "new _ ".

    Thanks,

    Subramanya

  • Community Member Profile Picture
    on at

    Dear Subramanya

    Thanks for your response

    I had also tried with "new_testacc"  while debugging it show status code 404 error.

  • Suggested answer
    Sanjaya Prakash Pradhan Profile Picture
    2,745 User Group Leader on at

    Follow this link to create record using REST OData so that you can cross verify if you are missing something.

     

    If this solution worked Mark as answer to close the thread.

    Dynamics CRM Training | Visit My Blog | Subscribe YouTube Channel | Like on Facebook

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Can you share your code that caused this error?

  • Community Member Profile Picture
    on at

    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));

    }

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Can you please add a line that calls that method? Without it all the rest of the code looks fine.

  • Community Member Profile Picture
    on at

    Thankyou for your response

    But i did't get my answer . basically i want to create a custom entity through api.

  • Community Member Profile Picture
    on at

    <script>

       $(document).ready(function ()

       {

           alert('On Page');

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

           var entityType = "new_testacc";

           var entityData = { "name": "bnkac" , "phone": "787897" };

           CreateEntity();

       });

    </script>

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    You didn't get your answer because you have posted not all the code. Let me rephrase what I wrote in my previous reply:

    1. Code that you posted demonstrates generic method that creates records through webapi and it looks good for me.

    2. To resolve your issue you should post code that calls that method. Without it unfortunately it's impossible to help you.

    It should look like something following:

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

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans