Skip to main content
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

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. 

  • Bahalzamon Profile Picture
    on at
    RE: Create Record with Lookup

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

  • Verified answer
    Guido Preite Profile Picture
    54,082 Moderator on at
    RE: Create Record with Lookup

    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
    on at
    RE: Create Record with Lookup

    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)

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

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans