Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Getting a Lookup (User) from a text field

Posted on by 509

I've a custom entity which is being populated from a third party App.

We (hopefully) will have the agent's email address as a text field in that custom entity.

I need to take that email address, and get the corresponding user in Dynamics and populate an entity what that user.

Is this simple to do with JavaScript? If so could someone please point me in the right direction, or if not direct me to an alternative.

Thanks

Lee

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Getting a Lookup (User) from a text field

    Hello Lee,

    Issue with JavaScript that it is executed on the frontend so only when user opens the form.

    I believe that thirdparty app will populate the field using the API so... clientside approach is not the perfect answer.

    I would recommend to write a plugin that will handle create/update of your record with email address, does the lookup of user based on the email and populate the lookup.

    Alternatively you can use "Power Automate" (former "Flow") if you don't have developer or developer skills.

    Good luck.

  • T.I.A Profile Picture
    T.I.A 1,760 on at
    RE: Getting a Lookup (User) from a text field

    try using the retrieve multiple, which you can filter on fields, for example

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/contacts?$filter=_owninguser_value eq 34b19a0b-ad6e-48fb-968d-77334f5e5dfe", true);

    req.setRequestHeader("OData-MaxVersion", "4.0");

    req.setRequestHeader("OData-Version", "4.0");

    req.setRequestHeader("Accept", "application/json");

    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

    req.onreadystatechange = function() {

       if (this.readyState === 4) {

           req.onreadystatechange = null;

           if (this.status === 200) {

               var results = JSON.parse(this.response);

               for (var i = 0; i < results.value.length; i++) {

                   var contactid = results.value[i]["contactid"];

               }

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

  • Lee-Martin Profile Picture
    Lee-Martin 509 on at
    RE: Getting a Lookup (User) from a text field

    Thanks

    REST queries I have no issue with.

    However I've no idea how to use it with a Lookup

  • Suggested answer
    T.I.A Profile Picture
    T.I.A 1,760 on at
    RE: Getting a Lookup (User) from a text field

    You can use a REST query to achieve this, it's fairly straight forward. if you don't know already look into this tool which makes building queries super fast

    github.com/.../CRMRESTBuilder

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans