title: How to properly set lookup value in CRM 2011? I'm only getting halfway
body: <p>After a lot of scouring for answers and experimenting I finally managed to put together something that doesn't end in complete fail. It can be seen below.</p>
  
  <pre><code>// set value in form field
  function setLookup(lookupSchemaName, lookupGuid, lookupValue, lookupEntity)
  {
      //var lookupSchemaName = 'uomid';
      //var lookupGuid   = '270BD3DB-D9AF-4782-9025-509E298DEC0A';
      //var lookupValue  = 'EACH';
      //var lookupEntity = 'unit';
  
      Xrm.Page.getAttribute(lookupSchemaName).setValue([{id: lookupGuid, name: lookupValue, entityType: lookupEntity}]);
  }
  </code></pre>
  
  <p>This is attached to the onChange event of the product lookup field. It <em>works</em> but not completely. The problem is that when it runs I end up with a lookup field that contains the word 'EACH' and is highlighted in blue (indicative of a link being made with the record behind it; see image below) but is not fully accepted. It's a state of limbo so to speak.</p>
  
  <p>What I expect to get is the entity's icon and a clickable value. I'm also unable to save the form but I can use the regular lookup function for the field and get things back to normal.</p>
  
  <p><img src="https://i.stack.imgur.com/xQEkR.png" alt="Field state after value insertion"></p>