0

My problem is that when I get the value of the lookup field ('Attachment') its retrieved as an array and I don't know how to deal with it, I mean how do I get the values inside this array, so any suggestions?

Here is the call function I use:

private _getListItems(): Promise<IAnnouncementItem[]> {
    return this.context.spHttpClient.get(
      this.context.pageContext.web.absoluteUrl + `/_api/web/lists/getbytitle('Circulations')/items?$select=ID,Attachment/ID&$expand=Attachment`,
      SPHttpClient.configurations.v1)
      .then(response => {
        debugger;
        return response.json();
      })
      .then(jsonResponse => {
        return jsonResponse.value;
      }) as Promise<IAnnouncementItem[]>;      
}

1 Answer 1

1

In general column values are available as follows:

response.value[0].Id

and lookup should be accessible as

response.value[0].Attachment.Id

Please check this MS Article explaining how to fetch and render the data. You can check _getListData and _renderList methods how response is extracted(though it's not lookup but will give you glimpse of data extraction). Using console\debugger you can check how array is stored at runtime. If you have already done that please ignore.

And I prefer to use pnp/sp (open source) as it simplifies coding, instead of using spHttpClient.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.