Set Lookup Field in Java Script

Yawer IqbalDyn365CE5 years ago159 Views

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

Original Post https://yaweriqbal.com/2020/11/05/set-lookup-field-in-java-script/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Top Headlines
    Join Us
    • X Network2.1K
    • LinkedIn3.8k
    • Bluesky0.5K
    Support The Site
    Events
    November 2025
    MTWTFSS
          1 2
    3 4 5 6 7 8 9
    10 11 12 13 14 15 16
    17 18 19 20 21 22 23
    24 25 26 27 28 29 30
    « Oct   Dec »
    Follow
    Search
    Popular Now
    Loading

    Signing-in 3 seconds...

    Signing-up 3 seconds...