Get column value, not ID, from a look up column
-
08-02-2021 - |
Вопрос
thank you for reading; my problem is:
I want to retrieve the values of the column "GroupWithPriority". That column is a Look Up from other list.
When I try to get the value, all I get is "GroupWithPriorityId" that gives only a number when I want to get the text... is it possible to do what I want?
I want to get "Group 1" but instead I get
I have already reached a lot and I found nothing :c
I would appreciate your response even if that means that there is no way to do what I want, thank you
My retrievement code looks something like this:
this.context.spHttpClient.get(requestUrl, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
if (response.ok) {
response.json().then((responseJSON) => {
if (responseJSON!=null && responseJSON.value!=null){
console.log(responseJSON.value);
}
});
}
});
Решение
In order to access values from the lookup column from a REST query, you need to add the $expand
parameter to your REST URI to specify the name of the column to expand, then reference the fields in your $select
prefixed with the Lookup columns name, the /
character and the name of the field from the reference lookup item you wish to select. For example:
/_api/web/lists(guid'<guid>')/items?$select=Title,ID,LookupField/FieldInTargetList&$expand=LookupField