Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Unable to set lookup field value using Xrm.WebApi.online.createRecord

Posted on by 15

I'm creating new record using Xrm.WebApi.online.createRecord. I'm adding lookup field value while creating record. See my code below. In the code, new_engagementsector is my lookup field name, 'new_sectors' is the name of lookup entity & 'cr0f8_engagements' is my entity name in which i am adding record.

var entity = {};
entity["new_engagementsector@odata.bind"] = "/new_sectors(97511775-8737-ea11-a813-000d3a0a827e)";

Xrm.WebApi.online.createRecord("cr0f8_engagements", entity).then(
function success(result) {
var newEntityId = result.id;
},
function(error) {
Xrm.Utility.alertDialog(error.message);
});

Its giving below error,

An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property 'new_engagementsector' which only has property annotations in the payload but no property value was found in the payload.

Is there anything missing in code? please help.

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Unable to set lookup field value using Xrm.WebApi.online.createRecord

    Hi,

    To update a lookup field, you should use field schema name.

    You can find schema name property in entity > fields.

    pastedimage1579158137931v1.png

    In most of cases, it will contains some upper case characters.

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Unable to set lookup field value using Xrm.WebApi.online.createRecord

    Hello,

    You need to use schema name of the field instead of logical name.

    entity["SchemaNameofthefield@odata.bind"] = "/new_sectors(97511775-8737-ea11-a813-000d3a0a827e)";

    Please check below link.

    community.dynamics.com/.../create-record-of-custom-entity-through-web-api

  • Suggested answer
    Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 User Group Leader on at
    RE: Unable to set lookup field value using Xrm.WebApi.online.createRecord

    Hello Vishal,

    Everything looks good but please make sure you are using the schema name for "new_engagementsector" field.

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans