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 365 | Integration, Dataverse...
Answered

Create Record with Lookup

(0) ShareShare
ReportReport
Posted on by 2

I have gone through many posts on here and I have not gotten any to work. So obviously I am doing something wrong.

I have 2 custom tables, new_pres_client (Pres_Client) & new_presclienthistory (Pres Client History)

I am attempting to create a record in the new_presclienthistory table when a change happens on the new_pres_client record.

If I just fill in the changes column it works fine, but when attempting to fill in the Lookup I get continuous errors.

function createClientHistory_OnSave() {
	varcurID = Xrm.Page.data.entity.getId().slice(1,-1);
	var newRecord = 
	{
		"new_changes": "Some Random Text",
		"new_client@odata.bind": "/new_pres_clients("   varcurID   ")"
	}
	Xrm.WebApi.createRecord("new_presclienthistory", newRecord);
}

Error:

An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property 'new_client' 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.

During my troubleshooting if I change the "new_client" to anything else I receive the same error.

Thank you for any assistance. 

I have the same question (0)
  • Bahalzamon Profile Picture
    2 on at

    OK, so I have been going through the documentation and from what I can tell I am following it to the letter, so I must be missing something. Below is the Microsoft example and mine, I'm not seeing where the issue is.

    Example: docs.microsoft.com/.../createrecord

    //Microsoft
    var data =
        {
            //text field to change
            "name": "Sample Account",
            //the Logical Name of the column "primarycontactid"
            //the EntitySetName of the lookup "contacts"
            "primarycontactid@odata.bind": "/contacts(465b158c-541c-e511-80d3-3863bb347ba8)"
        }
    //the Logical Name of the written to table "account"
    Xrm.WebApi.createRecord("account", data)
    
    //Mine
    var data =
        {
            //text field to change
            "new_changes": "Sample Account",
            //the Logical Name of the column "new_client"
            //the EntitySetName of the lookup "new_pres_clients"
            "new_client@odata.bind": "/new_pres_clients(465b158c-541c-e511-80d3-3863bb347ba8)"
        }
    //the Logical Name of the written to table "new_presclienthistory"
    Xrm.WebApi.createRecord("new_presclienthistory", data)

  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    can you try with my tool Dataverse REST Builder how the Xrm.WebApi syntax is generated?

    If I remember correctly there goes the navigation property

  • Bahalzamon Profile Picture
    2 on at

     Guido Preite  Yup, that fixed it, I was so close.

    Here is the fixed code:

    var curID = Xrm.Page.data.entity.getId().slice(1,-1);
    var record = {};
    record.new_changes = "List of Edits"; //Multiline Text
    record["new_Client@odata.bind"] = "/new_pres_clients(" curID ")"; //Lookup
    Xrm.WebApi.online.createRecord("new_presclienthistory", record);

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 365 | Integration, Dataverse, and general topics

#1
iampranjal Profile Picture

iampranjal 51

#2
Martin Dráb Profile Picture

Martin Dráb 39 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 26 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans