Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

How to set lookup based on text field input

Posted on by 10

I am having one field "Sales person " in which data is coming from Navision.

Note: Sales Person in Navision is User in CRM

Now there is another lookup field "Sales Agent" looking on Users.

If "Sales Person" field contains a name lets say "Ram" then I want to set the lookup field "Sales Agent" to "Ram".


Needed on priority basis , please share the sample code as I am new to plugins.

  • Verified answer
    RE: How to set lookup based on text field input

     Akash P ,

    You can try the below code,

    Hope it helps

    function setLookup(formContext) {
        formContext = formContext.getFormContext();
    
        var entity = "systemusers";
        var query = "?$filter=contains(fullame,'Ram')";
    
        var salesAgentField = formContext.getAttribute("salesAgent");
        var salesAgentLookup;
        Xrm.WebApi.retrieveMultipleRecords(entity, query).then(
            function success(result) {
                if (result !== null) {
                    // setting Lookup field value
                    salesAgentLookup = [];
                    salesAgentLookup[0] = {};
                    salesAgentLookup[0].id = result.entities[0].id;
                    salesAgentLookup[0].name = result.entities[0].fullname;
                    salesAgentLookup[0].entityType = "systemusers";
                    salesAgentField.setValue(salesAgentLookup);
                }
            },
            function (error) {
                console.log(error.message);
            }
        );
    }

    if this answer helps you, don't forget like and verify my answer

  • Akash P Profile Picture
    Akash P 10 on at
    RE: How to set lookup based on text field input

    Hi Tamilarasu Arunachalam 

    Can you please share the code, I don't have much idea as I am pretty new.

  • Verified answer
    RE: How to set lookup based on text field input

    Hi Akash P ,

           retrieve the users table with that name(came from NAV) with the filter as $filter=contains(Name,'Ram') and get that record ID and use that ID to set the value in the lookup

    If this answers helps you, like and verify my answer 

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans