Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Unable to set certain fields on entity creation

Posted on by Microsoft Employee

Hi all,

I am trying to use the Dynamics web API to create a simple lead entity.  I'm having trouble with my request based on a field I'm trying to set.  The request looks like:

POST https://<org>.crm.dynamics.com/api/data/v9.0/leads

{
"subject": "topic",
"lastname": "lastname",
"accountid@odata.bind": "/accounts(<GUID>)"
}

It's the last field that is tripping me up.  I know that in order to create an entity reference the format must be in the form above, and indeed this does work with other fields (such as contactid).  The error I'm seeing is:

{
"error": {
"code": "0x0",
"message": "An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property 'accountid' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values."

}

What could I be doing wrong? I've already referenced

 https://community.dynamics.com/crm/f/117/t/203648 ,

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/create-entity-web-api#associate-entities-on-create 

to no avail.

Thanks for any and all help.  

*This post is locked for comments

  • justjags Profile Picture
    justjags 17 on at
    RE: Unable to set certain fields on entity creation
    [quote user="Arun Vinoth"]

    You have to use the single valued navigation property customerid_accountcustomerid_contact@odata.bind to map. There’s no accountid property.

    docs.microsoft.com/.../lead

    Try to use CRM Rest builder to avoid such issues.

    [/quote]

    Thanks! This was driving me nuts.

    Nowhere in CRM or even webservice metadata XML was this navigation property name correctly visible.

  • Suggested answer
    SSamuel Profile Picture
    SSamuel 15 on at
    RE: Unable to set certain fields on entity creation

    Please try to provide the schema name of the look up. Note, that this is case sensitive.

    "AccountId@odata.bind": "/accounts(<GUID>)"
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Unable to set certain fields on entity creation

    Hi,

    I am also facing the same issue while creating record in an entity. I have used CRM rest builder to achieve this but no success.

    If I am not including any lookup field while creating record, it creates the record successfully. But not creates the record if lookup is included.

    Can anyone suggest what is the reason for this?

    Thanks

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Unable to set certain fields on entity creation

    Hi,

    If you are trying to set the value for Existing Account field then you can use the below code (generated from rest builder)-

    ================

    var entity = {};

    entity.subject = "test";

    entity.lastname = "test last";

    entity["parentaccountid@odata.bind"] = "/accounts(F6E4610A-8D9B-E811-811E-E0071B685A91)";

    var req = new XMLHttpRequest();

    req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/leads", true);

    req.setRequestHeader("OData-MaxVersion", "4.0");

    req.setRequestHeader("OData-Version", "4.0");

    req.setRequestHeader("Accept", "application/json");

    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    req.onreadystatechange = function() {

       if (this.readyState === 4) {

           req.onreadystatechange = null;

           if (this.status === 204) {

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

               var regExp = /\(([^)]+)\)/;

               var matches = regExp.exec(uri);

               var newEntityId = matches[1];

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

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

    ==================

    Hope this helps.

  • Suggested answer
    Arun Vinoth Profile Picture
    Arun Vinoth 11,613 on at
    RE: Unable to set certain fields on entity creation

    You have to use the single valued navigation property customerid_accountcustomerid_contact@odata.bind to map. There’s no accountid property.

    docs.microsoft.com/.../lead

    Try to use CRM Rest builder to avoid such issues.

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    RE: Unable to set certain fields on entity creation

    Hi pikav,

    Try using this instead.

    POST https://<org>.crm.dynamics.com/api/data/v9.0/leads
    
    ```
    
    {
    "subject": "topic",
    "lastname": "lastname",
    "accountid@odata.bind": "http://[Organization URI]/api/data/v9.0/accounts(<GUID>)"
    }

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans