Quantcast
Viewing all articles
Browse latest Browse all 82002

Lookup field not saving when populated by Javascript

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);        
     
   }
}


Viewing all articles
Browse latest Browse all 82002

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>