web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Get lookup fields by using Rest builder

(0) ShareShare
ReportReport
Posted on by 425

Hi experts,

I want to retrieve lookup fields(multiple records) data and set in single line of text field by using rest builder.

Thanks in advacne. 

I have the same question (0)
  • elmaslouhi1 Profile Picture
    187 on at

    Hi partner,

    to assist you, show us what you have tried to do to better understand the matter.

    Thank you

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi NB,

    As per my understanding, retrieving lookup fields data could be regarded as retrieving records of a specific entity,

    so we could run code below to achieve your requirement:(initialize a variable, then append retrieved name value to that variable in for loop)

    // var entity_type = formContext.getAttribute("lookupfield_name").getValue()[0].entityType;
    
    var list = "";
    
    var req = new XMLHttpRequest();
    req.open("GET", formContext.context.getClientUrl()   "/api/data/v9.1/accounts?$select=name", 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 result = JSON.parse(this.response);
                for (var i = 0; i < result.value.length; i  ) {
                    if (i < result.value.length - 1) {
                        list  = result.value[i]["name"]   ", ";
                    } else {
                        list  = result.value[i]["name"];
                    }
                }
                formContext.getAttribute("new_introduction").setValue(list);
                console.log(list);
            } else {
                var result = JSON.parse(this.response);
                var alertStrings = { confirmButtonLabel: "Ok", text: result.error.message, title: "Error" };
                var alertOptions = { width: 200, height: 150 };
                Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then(
                    function success(result) {
                        console.log("Alert dialog closed");
                    },
                    function (error) {
                        console.log(error.message);
                    }
                );
            }
        }
    };
    req.send();

    e.g: Populate a custom single line of text field with all retrieved account records.

    pastedimage1590993716111v2.png

    Regards,

    Clofly

  • naresh babu Profile Picture
    425 on at

    Thanks Clofly.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 128 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 113

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans