Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Blogs / https://yaweriqbal.com/ / Set Lookup Field in Java Sc...

Set Lookup Field in Java Script

Haansi Profile Picture Haansi 1,431

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

Comments

*This post is locked for comments