title: Dynamics365 "LOOKUP CONTROL ERROR: Cannot add item of typename= to the lookup control" JavaScript Error
body: <p>We just inherited a MS Dynamics 365 CRM project. We've been making some progress, but it's definitely not our forte.</p>
  
  <p>We've got a form that pre-populates a number of fields. The JavaScript function "setLookupValue" is called to pre-populate the fields. This function is called frequently throughout the solution. It works in all other instances, except for this one field. When the function is called for this particular field, we're receiving the following JavaScript error:</p>
  
  <blockquote>
    <p>"LOOKUP CONTROL ERROR: Cannot add item of typename= to the lookup control".</p>
  </blockquote>
  
  <p>Here's the JS function:</p>
  
  <pre><code>setLookupValue: function (LookupId, Type, Id, Name) {
      var lookupReference = [];
      lookupReference[0] = {};
      lookupReference[0].id = Id;
      lookupReference[0].entityType = Type;
      lookupReference[0].name = Name;
      alert("SET LOOKUP DEBUG: Name = " + Name + ", Type = " + Type + ", ID = " + Id + ", LookupId = " + LookupId);
      Xrm.Page.getAttribute(LookupId).setValue(lookupReference);
  }
  </code></pre>
  
  <p>I feel like the JS function is solid, since it's working in numerous places throughout the solution. This leads me to think it's something related to the parameters (data) being passed in?</p>
  
  <p>I've done a bunch of research online, but am having a tough time getting this sorted.</p>
  
  <p>Thanks in advance for any assistance!</p>