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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Unable to set certain fields on entity creation

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    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>)"
    }
  • Suggested answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at

    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
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

  • Community Member Profile Picture
    on at

    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
    SSamuel Profile Picture
    15 on at

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

    "AccountId@odata.bind": "/accounts(<GUID>)"
  • justjags Profile Picture
    17 on at
    [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.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans