Question

I have a lookup list that contains a choice field.

I'm trying to retrieve it's values using rest

Expand= "list" Select= "list/ChoiceField"

I get

The query to field 'list/ChoiceField' is not valid."

Was it helpful?

Solution

Consider the following scenario:

List A with columns:

  • Title (Single Line Text)
  • ColumnA (Single Line Text)
  • ColumnB (Choice)

and

List B with columns:

  • Title (Single line of Text)
  • ColumnOne (Single line of Text)
  • ColumnX (Lookup From List A, column A mapped)

So the REST Query for List B would be:

https://<site url>/_api/web/lists/getbytitle('ListB')/Items?$expand=ColumnX&$select=Title,ColumnX,ColumnX/ColumnB

EDIT

The above concept doesnt work on choice type of column. For choice type column, you can use below concepts.

Concept 1: Use of hidden column (text), with Workflow/ER.

In this case, use Event Receiver (for SPO Webhook) or Workflow to read the value of choice column and update the hidden column with these values.
Pros: You can use the above query to expand the hidden column.
Cons: You need to have another steps in between, to convert content of choice column to text column.

Concept 2: Use List Field endpoint, instead of List Item endpoint. If you know the item ID of ListB item, then you can directly hit field endpoint to get all the column values of Lookup ListA.
Pros: No extra conversion method required as listed in concept 1.
Cons: Low on performance, as you require the item ID in this case.

Syntax:

https://<site url>/_api/web/lists/getbytitle('ListB')/Items(<item_id>)/ColumnX
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top