web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Lookup field not saving when populated by Javascript

(1) ShareShare
ReportReport
Posted on by 1,947 Most Valuable Professional

If I set the value of a lookup field using Javascript, it appears correctly on the form (name, icon, etc) but does not save when the user hits the save button.  The record does save, just not that field.  If I do it "manually" (ie - use the lookup control) it will save the field value.

I have done this a million times in code and for some reason, its not working CRM 2011, Rollup 11

Please note that I have shut off automatic resolutions and disabled "most recently used items" for the fields. The field is not read only, but I have tried with submitmode = 'always' as well with the same results.  I have also tried variations on "typename"  (e.g. used "entityType")  The field is even mandatory and the record still saves.

Any ideas?

Here is the code, the original was taken from a blog and its pretty standard:

// Set the value of a lookup field

function SetLookupValue(fieldName, id, name, entityType)
{
   
   if (fieldName != null)
   {
       
      var lookupValue = new Array();

      lookupValue[0] = new Object();
       
      lookupValue[0].id = id;
       
      lookupValue[0].name = name;
       
      lookupValue[0].typename = entityType;
       
      Xrm.Page.getAttribute(fieldName).setValue(lookupValue);        
     
   }
}

*This post is locked for comments

I have the same question (0)
  • adampfau Profile Picture
    Microsoft Employee on at

    Nick,

           No changes to the method of setting the lookup value on the form using JavaScript were implemented in UR11.  Also, I don't see any issues with the code that you are using above.  Have you tested this with UR12 or 13 and confirmed that you are still seeing the issue?

  • Nick.Doelman Profile Picture
    1,947 Most Valuable Professional on at

    Sorry, should have updated this post, I actually resolved the issue right after I posted it. I was passing the wrong value for "entity type" in my function.  All good now.

    Cheers

    Nick

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans