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.
Thanks Clofly.
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.
Regards,
Clofly
Hi partner,
to assist you, show us what you have tried to do to better understand the matter.
Thank you
Daivat Vartak (v-9d...
225
Super User 2025 Season 1
Muhammad Shahzad Sh...
106
Most Valuable Professional
Eugen Podkorytov
102