Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting list items with LoadListDataAsStreamAsync with CAML query won't allow to request RoleAssignments #607

Closed
pxmonti opened this issue Oct 31, 2021 · 17 comments
Assignees
Labels
area: model 📐 Related to the core SDK models question Further information is requested

Comments

@pxmonti
Copy link

pxmonti commented Oct 31, 2021

Hello all, I need to load all items from lists/libraries with potentially a large number of items and for this I thought I'd use a CAML query approach to extract only the fields I need and use RowLimit for pagination. Since I need also system fields like FieldRef and File_x0020_Size, I cannot use LoadItemsByCamlQueryAsync, because as per documentation this method won't return those.
LoadListDataAsStreamAsync would solve this, however I also need to fetch the RoleAssigments collection for every item, but this method won't return it (I checked that LoadItemsByCamlQueryAsync would return RoleAssigments correctly loaded instead).
So, basically looks like there's no way as of now (that I am awar of) to query items using a CAML query and have system fields fetched and have RoleAssigment fetched all with a single call.
I was able to do so with the old CSOM approach, so I was expecting I could do this with PnP.Core SDK too.
Is there a way to get to the result I'm trying to achieve?
Thank you

@jansenbe jansenbe self-assigned this Oct 31, 2021
@jansenbe jansenbe added area: model 📐 Related to the core SDK models question Further information is requested labels Oct 31, 2021
@jansenbe
Copy link
Contributor

Thanks for using @pxmonti and providing feedback.

For now this indeed is the case, I'll do some more research to understand if somehow the LoadItemsByCamlQuery approach can return the "system" fields...if not then I'm considering adding a another data load option that under the covers uses the CSOM endpoint.

@pxmonti
Copy link
Author

pxmonti commented Oct 31, 2021

Thank you @jansenbe. For the time being I'll stick with the current CSOM approach and wait for news from your side.

@jansenbe
Copy link
Contributor

That makes sense @pxmonti. I'll add a new issue to track the need

@jansenbe
Copy link
Contributor

@pxmonti : can you share the CSOM snippet you're using today? Will help with ensuring we verify your use case.

@pxmonti
Copy link
Author

pxmonti commented Oct 31, 2021

Sure, this is what I currently do with CSOM:

``

      CamlQuery camlQuery = new CamlQuery();
      camlQuery.SetViewAttribute(QueryScope.RecursiveAll);
      camlQuery.SetViewFields(new string[] { "ID",
				          "Title",
				          "FileRef",
				          "Author",
				          "Editor",
				          "Created",
				          "Modified",
				          "File_x0020_Size"});
        camlQuery.SetQueryRowlimit(1000u);
        ListItemCollectionPosition position = null;
        do
        {
            camlQuery.ListItemCollectionPosition = position;
            ListItemCollection listItems = spList.GetItems(camlQuery);
            context.Load(listItems, lits => lits.Include(
	            item => item.DisplayName,
	            item => item.HasUniqueRoleAssignments,
	            item => item.FileSystemObjectType,
	            item => item.Id,
	            item => item.RoleAssignments)
	            );
        
            try
            {
	            context.ExecuteQueryRetry(10, 500, decoration);
            }
            catch (Exception ex)
            {
	            // Logging exceptions
            }
            position = listItems.ListItemCollectionPosition;
            /*
            ... Do something with the items
            */
        } while( position != null);

``

@jansenbe
Copy link
Contributor

jansenbe commented Oct 31, 2021

Adding some research notes here: using $select and $expand kind of works in combination with the GetItems call as shown in below request.

  • Fields on the SP.ListItem (e.g. HasUniqueRoleAssignments) can be just added via $select, not needed to include them in the CAML query
  • Regular list specific fields (e.g MyCustomField) need to be defined in just the CAML query ViewFields to show up in the results. Adding them also in the $select statement does not impact the results, only adding them in the $select does not return the field value
  • List "system" fields (e.g. FileDirRef) need to be defined in both the CAML query ViewFields and in the $select statement before they show in the result set
  • Collections (e.g. RoleAssignments) only have to be added via $expand. Adding them also the CAML query does not impact the result. Only adding them in the CAML query does not return the collection values.
  • Collections can (selectively) expand child collections like with any other REST expand operation

Implementation proposal:

  • Add override for LoadItemsByCamlQuery that adds an additional parameter params Expression<Func<IListItem, object>>[] selectors
  • See BuildGetCommentsApiCallAsync in listitem.cs for how the query engine can be integrated to translate the expression in $select and $expand statements
  • Optional add extra validation to verify above defined rules

Sample
Request: https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/GetItems?$select=*,FileDirRef,File_x0020_Type,HasUniqueRoleAssignments&$expand=RoleAssignments

Body:

{
    "query": {
        "__metadata": {
            "type": "SP.CamlQuery"
        },
        "ViewXml": "<View><ViewFields><FieldRef Name='Title' /><FieldRef Name='FileDirRef' /><FieldRef Name='File_x0020_Type' /></ViewFields><OrderBy Override='TRUE'><FieldRef Name= 'ID' Ascending= 'FALSE' /></OrderBy></View>",
        "DatesInUtc": true
    }
}

Results in an expanded RoleAssignments + "system" fields like FileDirRef and File_x0020_Type:

{
    "d": {
        "results": [
            {
                "__metadata": {
                    "id": "3d5d7814-a5c7-4f66-9505-ba9f7bad0c41",
                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)",
                    "etag": "\"107\"",
                    "type": "SP.Data.FieldTypesListItem"
                },
                "FirstUniqueAncestorSecurableObject": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/FirstUniqueAncestorSecurableObject"
                    }
                },
                "RoleAssignments": {
                    "results": [
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(3)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(3)",
                                "type": "SP.RoleAssignment"
                            },
                            "Member": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(3)/Member"
                                }
                            },
                            "RoleDefinitionBindings": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(3)/RoleDefinitionBindings"
                                }
                            },
                            "PrincipalId": 3
                        },
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(4)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(4)",
                                "type": "SP.RoleAssignment"
                            },
                            "Member": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(4)/Member"
                                }
                            },
                            "RoleDefinitionBindings": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(4)/RoleDefinitionBindings"
                                }
                            },
                            "PrincipalId": 4
                        },
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(5)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(5)",
                                "type": "SP.RoleAssignment"
                            },
                            "Member": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(5)/Member"
                                }
                            },
                            "RoleDefinitionBindings": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(5)/RoleDefinitionBindings"
                                }
                            },
                            "PrincipalId": 5
                        },
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(6)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(6)",
                                "type": "SP.RoleAssignment"
                            },
                            "Member": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(6)/Member"
                                }
                            },
                            "RoleDefinitionBindings": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(6)/RoleDefinitionBindings"
                                }
                            },
                            "PrincipalId": 6
                        },
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(16)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(16)",
                                "type": "SP.RoleAssignment"
                            },
                            "Member": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(16)/Member"
                                }
                            },
                            "RoleDefinitionBindings": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(16)/RoleDefinitionBindings"
                                }
                            },
                            "PrincipalId": 16
                        },
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(44)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(44)",
                                "type": "SP.RoleAssignment"
                            },
                            "Member": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(44)/Member"
                                }
                            },
                            "RoleDefinitionBindings": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(44)/RoleDefinitionBindings"
                                }
                            },
                            "PrincipalId": 44
                        },
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(47)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(47)",
                                "type": "SP.RoleAssignment"
                            },
                            "Member": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(47)/Member"
                                }
                            },
                            "RoleDefinitionBindings": {
                                "__deferred": {
                                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(47)/RoleDefinitionBindings"
                                }
                            },
                            "PrincipalId": 47
                        }
                    ]
                },
                "AttachmentFiles": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/AttachmentFiles"
                    }
                },
                "ContentType": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/ContentType"
                    }
                },
                "GetDlpPolicyTip": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/GetDlpPolicyTip"
                    }
                },
                "FieldValuesAsHtml": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/FieldValuesAsHtml"
                    }
                },
                "FieldValuesAsText": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/FieldValuesAsText"
                    }
                },
                "FieldValuesForEdit": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/FieldValuesForEdit"
                    }
                },
                "File": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/File"
                    }
                },
                "Folder": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/Folder"
                    }
                },
                "LikedByInformation": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/LikedByInformation"
                    }
                },
                "ParentList": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/ParentList"
                    }
                },
                "Properties": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/Properties"
                    }
                },
                "Versions": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/Versions"
                    }
                },
                "HasUniqueRoleAssignments": false,
                "FileSystemObjectType": 0,
                "Id": 1,
                "ServerRedirectedEmbedUri": null,
                "ServerRedirectedEmbedUrl": "",
                "Title": "item updated",
                "FileDirRef": "/sites/prov-1/Lists/FieldTypes",
                "File_x0020_Type": null,
                "ID": 1,
                "Created": "2020-11-10T15:39:12Z",
                "Modified": "2021-10-26T07:16:02Z"
            }
        ]
    }
}

Sample that also further expands RoleAssignments and loads the Id property of each RoleDefinition:

https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/GetItems?$select=*,FileDirRef,File_x0020_Type,HasUniqueRoleAssignments,Number,RoleAssignments/PrincipalId&$expand=RoleAssignments,RoleAssignments/RoleDefinitionBindings

Results in:

{
    "d": {
        "results": [
            {
                "__metadata": {
                    "id": "7100a7ee-f6ed-4176-aefb-5d9522c971d9",
                    "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)",
                    "etag": "\"107\"",
                    "type": "SP.Data.FieldTypesListItem"
                },
                "FirstUniqueAncestorSecurableObject": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/FirstUniqueAncestorSecurableObject"
                    }
                },
                "RoleAssignments": {
                    "results": [
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(3)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(3)",
                                "type": "SP.RoleAssignment"
                            },
                            "RoleDefinitionBindings": {
                                "results": [
                                    {
                                        "__metadata": {
                                            "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741829)",
                                            "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741829)",
                                            "type": "SP.RoleDefinition"
                                        },
                                        "BasePermissions": {
                                            "__metadata": {
                                                "type": "SP.BasePermissions"
                                            },
                                            "High": "2147483647",
                                            "Low": "4294967295"
                                        },
                                        "Description": "Has full control.",
                                        "Hidden": false,
                                        "Id": 1073741829,
                                        "Name": "Full Control",
                                        "Order": 1,
                                        "RoleTypeKind": 5
                                    }
                                ]
                            },
                            "PrincipalId": 3
                        },
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(4)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(4)",
                                "type": "SP.RoleAssignment"
                            },
                            "RoleDefinitionBindings": {
                                "results": [
                                    {
                                        "__metadata": {
                                            "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741826)",
                                            "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741826)",
                                            "type": "SP.RoleDefinition"
                                        },
                                        "BasePermissions": {
                                            "__metadata": {
                                                "type": "SP.BasePermissions"
                                            },
                                            "High": "176",
                                            "Low": "138612833"
                                        },
                                        "Description": "Can view pages and list items and download documents.",
                                        "Hidden": false,
                                        "Id": 1073741826,
                                        "Name": "Read",
                                        "Order": 128,
                                        "RoleTypeKind": 2
                                    }
                                ]
                            },
                            "PrincipalId": 4
                        },
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(5)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(5)",
                                "type": "SP.RoleAssignment"
                            },
                            "RoleDefinitionBindings": {
                                "results": [
                                    {
                                        "__metadata": {
                                            "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741830)",
                                            "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741830)",
                                            "type": "SP.RoleDefinition"
                                        },
                                        "BasePermissions": {
                                            "__metadata": {
                                                "type": "SP.BasePermissions"
                                            },
                                            "High": "432",
                                            "Low": "1011030767"
                                        },
                                        "Description": "Can add, edit and delete lists; can view, add, update and delete list items and documents.",
                                        "Hidden": false,
                                        "Id": 1073741830,
                                        "Name": "Edit",
                                        "Order": 48,
                                        "RoleTypeKind": 6
                                    }
                                ]
                            },
                            "PrincipalId": 5
                        },
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(6)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(6)",
                                "type": "SP.RoleAssignment"
                            },
                            "RoleDefinitionBindings": {
                                "results": [
                                    {
                                        "__metadata": {
                                            "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741825)",
                                            "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741825)",
                                            "type": "SP.RoleDefinition"
                                        },
                                        "BasePermissions": {
                                            "__metadata": {
                                                "type": "SP.BasePermissions"
                                            },
                                            "High": "48",
                                            "Low": "134287360"
                                        },
                                        "Description": "Can view specific lists, document libraries, list items, folders, or documents when given permissions.",
                                        "Hidden": true,
                                        "Id": 1073741825,
                                        "Name": "Limited Access",
                                        "Order": 160,
                                        "RoleTypeKind": 1
                                    }
                                ]
                            },
                            "PrincipalId": 6
                        },
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(16)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(16)",
                                "type": "SP.RoleAssignment"
                            },
                            "RoleDefinitionBindings": {
                                "results": [
                                    {
                                        "__metadata": {
                                            "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741825)",
                                            "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741825)",
                                            "type": "SP.RoleDefinition"
                                        },
                                        "BasePermissions": {
                                            "__metadata": {
                                                "type": "SP.BasePermissions"
                                            },
                                            "High": "48",
                                            "Low": "134287360"
                                        },
                                        "Description": "Can view specific lists, document libraries, list items, folders, or documents when given permissions.",
                                        "Hidden": true,
                                        "Id": 1073741825,
                                        "Name": "Limited Access",
                                        "Order": 160,
                                        "RoleTypeKind": 1
                                    }
                                ]
                            },
                            "PrincipalId": 16
                        },
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(44)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(44)",
                                "type": "SP.RoleAssignment"
                            },
                            "RoleDefinitionBindings": {
                                "results": [
                                    {
                                        "__metadata": {
                                            "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741829)",
                                            "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741829)",
                                            "type": "SP.RoleDefinition"
                                        },
                                        "BasePermissions": {
                                            "__metadata": {
                                                "type": "SP.BasePermissions"
                                            },
                                            "High": "2147483647",
                                            "Low": "4294967295"
                                        },
                                        "Description": "Has full control.",
                                        "Hidden": false,
                                        "Id": 1073741829,
                                        "Name": "Full Control",
                                        "Order": 1,
                                        "RoleTypeKind": 5
                                    }
                                ]
                            },
                            "PrincipalId": 44
                        },
                        {
                            "__metadata": {
                                "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(47)",
                                "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/RoleAssignments/GetByPrincipalId(47)",
                                "type": "SP.RoleAssignment"
                            },
                            "RoleDefinitionBindings": {
                                "results": [
                                    {
                                        "__metadata": {
                                            "id": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741833)",
                                            "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/RoleDefinitions(1073741833)",
                                            "type": "SP.RoleDefinition"
                                        },
                                        "BasePermissions": {
                                            "__metadata": {
                                                "type": "SP.BasePermissions"
                                            },
                                            "High": "560",
                                            "Low": "134221824"
                                        },
                                        "Description": "Can only view the web when given permissions.",
                                        "Hidden": true,
                                        "Id": 1073741833,
                                        "Name": "Web-Only Limited Access",
                                        "Order": 176,
                                        "RoleTypeKind": 9
                                    }
                                ]
                            },
                            "PrincipalId": 47
                        }
                    ]
                },
                "AttachmentFiles": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/AttachmentFiles"
                    }
                },
                "ContentType": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/ContentType"
                    }
                },
                "GetDlpPolicyTip": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/GetDlpPolicyTip"
                    }
                },
                "FieldValuesAsHtml": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/FieldValuesAsHtml"
                    }
                },
                "FieldValuesAsText": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/FieldValuesAsText"
                    }
                },
                "FieldValuesForEdit": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/FieldValuesForEdit"
                    }
                },
                "File": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/File"
                    }
                },
                "Folder": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/Folder"
                    }
                },
                "LikedByInformation": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/LikedByInformation"
                    }
                },
                "ParentList": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/ParentList"
                    }
                },
                "Properties": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/Properties"
                    }
                },
                "Versions": {
                    "__deferred": {
                        "uri": "https://bertonline.sharepoint.com/sites/prov-1/_api/Web/Lists(guid'7d644d41-d86e-4594-99de-479594a68fd9')/Items(1)/Versions"
                    }
                },
                "HasUniqueRoleAssignments": false,
                "FileSystemObjectType": 0,
                "Id": 1,
                "ServerRedirectedEmbedUri": null,
                "ServerRedirectedEmbedUrl": "",
                "Title": "item updated",
                "FileDirRef": "/sites/prov-1/Lists/FieldTypes",
                "File_x0020_Type": null,
                "Number": 123456,
                "ID": 1,
                "Created": "2020-11-10T15:39:12Z",
                "Modified": "2021-10-26T07:16:02Z"
            }
        ]
    }
}

@jansenbe
Copy link
Contributor

@pxmonti : what you need is possible using REST (see above)...I'll work on implementing this in the coming days.

@pxmonti
Copy link
Author

pxmonti commented Oct 31, 2021 via email

@jansenbe
Copy link
Contributor

jansenbe commented Nov 2, 2021

@pxmonti : I've just pushed a fix for this (see 3468711). With tomorrow's nightly build you should be able to mimic your CSOM scenario. Updated docs will come to https://pnp.github.io/pnpcore/using-the-sdk/listitems-intro.html

@pxmonti
Copy link
Author

pxmonti commented Nov 2, 2021

This is great news! Thank you @jansenbe !!
So, if I am understanding correctly, it will be possible to include system fields in the <FieldRef ...... /> section of the CAML query XML definition and they will be extracted too, correct? And for the RoleAssigmnents? Is there anything particular to be done in the method call to fetch these too? Maybe I should simply wait for the documentation to be updated and read these details from there.
Thanks again.

@jansenbe
Copy link
Contributor

jansenbe commented Nov 2, 2021

@pxmonti : yes, just add the system fields as FieldRef's in your CAML query. The code will analyze the CAML XML and ensure the needed fields are added into the $select. Checkout https://pnp.github.io/pnpcore/using-the-sdk/listitems-intro.html#using-paging-with-loaditemsbycamlquery for a sample. Note the highlighted parts:
image

@pxmonti
Copy link
Author

pxmonti commented Nov 2, 2021

Awesome! I'll install the next nightly build package and test in in my code!
Thank you @jansenbe

@pxmonti
Copy link
Author

pxmonti commented Nov 3, 2021

Hi @jansenbe , I've tested the 1.4.34-nightly build and I see that it is 99% working as I was expecting.
I am still unable to fetch the "File_x0020_size" system field, while now I am able to fetch the FileRef field correctly.
I've even tried with item => item.File.Length but it doesn't work.
Here the excerpt of code I am using:

image

What is the correct way of extracting the "File_x0020_Size" field?

@jansenbe
Copy link
Contributor

jansenbe commented Nov 3, 2021

@pxmonti : You've to possible solutions. The red one uses the File_x0020_Size property, but you need to get it via also loading the FieldValuesAsText property. The green approach loads the File with only the Length property populated.

image

See also the updated paging sample in our docs: https://pnp.github.io/pnpcore/using-the-sdk/listitems-intro.html#using-paging-with-loaditemsbycamlquery

@pxmonti
Copy link
Author

pxmonti commented Nov 3, 2021

Hi @jansenbe , I tested the 2 approaches proposed.
The "red" approach works as a charm and that's enough for my case. A big THANK YOU!
However, just for your information, the "green" approach doesn't work for me because when I try to reference "QueryProperties" method of p.File there's no such method than can be selected and code won't compile.

I am using 1.4.34-nightly build.

@jansenbe
Copy link
Contributor

jansenbe commented Nov 3, 2021

@pxmonti : you need to add a using statement: "using PnP.Core.Model;" before you can use "QueryProperties"

@jansenbe
Copy link
Contributor

jansenbe commented Nov 3, 2021

If all is good, then feel free to close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: model 📐 Related to the core SDK models question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants