简体   繁体   中英

Filtering Fields in SharePoint QueryString

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%7D/items?expand=fields%28select%3DProduction_Code%29

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%7D/",
        "createdBy": {
            "user": {
                "email": "user_email@gmail.com",
                "displayName": "LastName, FirstName"
            }
        },
        "lastModifiedBy": {
            "user": {
                "email": "user_email@gmail.com",
                "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"
        },
        "fields@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.list)('%7MY_LIST%7D')/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%7D/items?filter=fields%2FProduction_Code%20eq%20%27ARCH0090%27&select=fields

However, the result set looks like so:

{
"@odata.context": ""https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.list)('%7MY_LIST%7D')/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": "."
        }

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",
            "fields@odata.context": "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 '.'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM