locked
Populate Lookup field (user) when onchange of field RRS feed

  • Question

  • I have a picklist field that when a particular value is selected, populates a lookup field with a particular user.  I can find the GUID for the user, but am not sure how to create onload script to populate the lookup field.  Does anyone have a script to do or suggestions?  Thanks in advance!
    Ken Compter
    Wednesday, March 9, 2011 2:09 AM

Answers

All replies

  • To populate a lookup field, first you use Xrm.Page.data.entity.attributes.get() to get a reference to the lookup attribute you want to set.

    Then you use the attribute's setValue() method to set the lookup's value. The value needs to be an array of lookup objects, that each contain an id, type, and name.

     

    This should do it:

     

    var attribute = Xrm.Page.data.entity.attributes.get("myUserLookup");

    var lookupItem =

    {

      "id": "{user id guid}",

      "type": "systemuser"

      "name": "John Smith"

    }

     

    attribute.setValue([lookupItem]);

     Edit: Ah yes, I was assuming CRM 2011. Use the link Pogo69 provided for CRM 4.0


    Erik Pool | Avanade XRM | http://erikpool.blogspot.com
    • Proposed as answer by Erik-lp Wednesday, March 9, 2011 2:39 AM
    Wednesday, March 9, 2011 2:38 AM
    • Marked as answer by kcompter Wednesday, March 9, 2011 1:58 PM
    Wednesday, March 9, 2011 2:39 AM
  • Thanks for the replies, worked like a charm!
    Ken Compter
    Wednesday, March 9, 2011 1:59 PM