Skip to main content
Community site session details

Community site session details

Session Id :
Customer Service forum

Unable to set account lookup field with Xrm.Webapi version 9 Dynamics 365

(0) ShareShare
ReportReport
Posted on by 141

I am setting two lookup fields (Contact and Account entity) while creating a custom entity record.

Once the recorded is created I can see Contact lookup is set on the form but not Account.

The Account lookup I am trying to link on custom entity record is related to Contact. 

I am using schema names for this purpose and have also tried to create the custom entity record first and then update this with Account record later but it wouldn't have it. 

Here is the code: 

try

{
  //create CR object
  var Obj= new Object();
  Obj.name = "ABC";
  Obj.changedescription = "Test Description";
  Obj["abc_Account@odata.bind"] = "/accounts("+ accountId +")";  //Doesn't work and no error

  Obj["abc_Contact@odata.bind"] = "/contacts("+ contactId +")";  //Works

  Xrm.WebApi.createRecord("abc_entity", Obj).then(function (result) {
            
            //get the guid of created record
            var recordId = result.id;
                       
            //below code is used to open the created record
            var windowOptions = {
                openInNewWindow: false
            };
            //check if XRM.Utility is not null
            if (Xrm.Utility != null) {

                //open the entity record
                Xrm.Utility.openEntityForm("abc_entity", recordId, null, windowOptions);
            }
        },
      function (error) {
          Xrm.Utility.alertDialog(error.message);
      });

    } catch (e) {
        Xrm.Utility.alertDialog(e.message);
}

Any suggestions would be welcome. 

Thanks

  • Suggested answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at
    RE: Unable to set account lookup field with Xrm.Webapi version 9 Dynamics 365

    Do you have audit enabled, can you verify if that value is set & clearing out again? May be some plugin or custom WF to clear this?

    Did you debug to see if the value being set in the creating entity?

  • Qaqa Profile Picture
    141 on at
    RE: Unable to set account lookup field with Xrm.Webapi version 9 Dynamics 365

    Hi Arun,

    Yes, it is strange. Its behaving same with other records too and happening always.

    Thanks

  • Arun Vinoth Profile Picture
    11,615 Moderator on at
    RE: Unable to set account lookup field with Xrm.Webapi version 9 Dynamics 365

    Interesting, is this happening for any particular record or always?

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Customer Service

Featured topics

Product updates

Dynamics 365 release plans