Home > Net >  Filtering Fields in SharePoint QueryString
Filtering Fields in SharePoint QueryString

Time:01-20

I am trying to query a specific item from a SharePoint list.

I have the following query string:

https://graph.microsoft.com/v1.0/sites/myCompany.sharepoint.com:/sites/Global:/lists/%7MY_LIST}/items?expand=fields(select=Production_Code)

This query returns a set of objects that looks like this:

"value": [
    {
        "@odata.etag": "\"000000-0000-4a29-0000-00000000,12\"",
        "createdDateTime": "2015-09-22T05:43:03Z",
        "eTag": "\"0000000-0000-0000-0000-00000000,12\"",
        "id": "0000",
        "lastModifiedDateTime": "2022-11-07T04:01:07Z",
        "webUrl": "https://graph.microsoft.com/v1.0/sites/myCompany.sharepoint.com:/sites/Global:/lists/%7MY_LIST}/",
        "createdBy": {
            "user": {
                "email": "[email protected]",
                "displayName": "LastName, FirstName"
            }
        },
        "lastModifiedBy": {
            "user": {
                "email": "[email protected]",
                "displayName": "LastName, FirstName"
            }
        },
        "parentReference": {
            "id": "0000000-0000-0000-0000-000000000",
            "siteId": "my_company.sharepoint.com,000000-0000-00000-000000-0000000--0000000"
        },
        "contentType": {
            "id": "0x0000000000000000000000000000000000000000000",
            "name": "Generic E-Mail"
        },
        "[email protected]": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.list)('%7MY_LIST}')/items('0000')/fields/$entity",
        "fields": {
            "@odata.etag": "\"000000-0000-4a29-0000-00000000,12\"",
            "Production_Code": "."
        }
    }]

Instead of all fields being returned, I want JUST the fields object, like below:

        "fields": {
            "@odata.etag": "\"000000-0000-4a29-0000-00000000,12\"",
            "Production_Code": "."
        }

To achieve this, I tried the following query:

https://graph.microsoft.com/v1.0/sites/myCompany.sharepoint.com:/sites/Global:/lists/%7MY_LIST}/items?filter=fields/Production_Code eq 'ARCH0090'&select=fields

However, the result set looks like so:

{
"@odata.context": ""https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.list)('%7MY_LIST}')/items",
"value": [
    {
        "@odata.etag": "\"000000-0000-0000-0000-0000000,11\""
    }
]

}

and omits fields that I requested as part of the query string. I have read through Microsoft's Documentation exhaustively in search of why this happens, but with no luck.

How do I create a query string that returns a fields object like so:

        "fields": {
            "@odata.etag": "\"000000-0000-4a29-0000-00000000,12\"",
            "Production_Code": "."
        }

CodePudding user response:

Try using the expand and select queries like so:

https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?expand=fields(select=Production_Code)

CodePudding user response:

The behavior is that fields are ignored in $select and default set of properties is returned.

I would expand fields and select only id.

https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/items?$expand=fields($select=Production_Code)&$select=id

The result will be:

{
    "value": [
        {
            "@odata.etag": "\"000000-0000-4a29-0000-00000000,12\"",
            "id": "0000",
            "[email protected]": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.list)('xxx')/items('yyy')/fields/$entity",
            "fields": {
                "@odata.etag": "\"000000-0000-4a29-0000-00000000,12\"",
                "Production_Code": "."
            }
        }
    ]
}

If you want to remove @odata.xxx attributes add header accept:application/json;odata.metadata=none to the request.

{
    "value": [
        {
            "id": "0000",
            "fields": {
                "Production_Code": "."
            }
        }
    ]
}

If you want to filter items by specific Production_Code and Production_Code column is indexed

https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/items?$expand=fields($select=Production_Code)&$select=id&$filter=fields/Production_Code eq '.'
  • Related