Set Lookup Field in Java Script

Adding this post for someone who needs it and for my own reference.

In Java Script lookup can be populated in one of three ways depending on requirements:

  1. Query lookup data to set in form
  2. Get lookup details from data available in form (from other fields)
  3. Hard code lookup values

This is example using second option. It uses logged in user’s id and name to populate lookup. A lookup can be populated by providing its id (GUID) , name and entity type.

var approver = new Array();
approver[0] = new Object();
approver[0].id = Xrm.Page.context.getUserId(); // Guid as "{a004b16f-4bae-4445-9b15-438449a170d3}"; 
approver[0].name = Xrm.Utility.getGlobalContext().getUserName();
approver[0].entityType = "systemuser";
Xrm.Page.getAttribute("sofhof_approvedby").setValue(approver);

I hope it is helpful.

Let’s Connect

 twIcon lnIcon fbicon

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s