Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Create Record with Lookup

Posted on by 215

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
    Bahalzamon 215 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
    Guido Preite 54,081 Super User 2024 Season 1 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
    Bahalzamon 215 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

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

Product updates

Dynamics 365 release plans