web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    RE: Error while creating custom entity using javascript

    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
    RE: Error while creating custom entity using javascript

    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
    RE: Error while creating custom entity using javascript

    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
    RE: Error while creating custom entity using javascript

    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
    RE: Error while creating custom entity using javascript

    Can you share your code that caused this error?

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

    }

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

    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
    RE: Error while creating custom entity using javascript

    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
    RE: Error while creating custom entity using javascript

    <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
    RE: Error while creating custom entity using javascript

    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

Responsible AI policies

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

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans