Kunoichi
Kunoichi

Reputation: 124

Department not null filter for IGraphServiceUsersCollectionRequest (GraphServiceClient)

How to create not null filter for department property to get users by GraphServiceClient?

department ne null

and

NOT(department eq null)

don't work

My current code:

var request = _graphClient.Users.Request()
    .Filter($"department ne null");
        
var usersPage = await request.GetAsync();

Upvotes: 0

Views: 564

Answers (1)

user2250152
user2250152

Reputation: 20748

Filtering by department requires adding header ConsistencyLevel:eventual and $count parameter must be set to true.

According to the documentation department is returned only on $select. It means that if you need to know the value of department you have to add Select method and specify all properties to be returned including department.

var queryOptions = new List<QueryOption>()
{
    new HeaderOption("ConsistencyLevel", "eventual");
    new QueryOption("$count", "true")
};

var request = await _graphClient.Users
    .Request( queryOptions )
    .Select("id,displayName,department") // and other properties
    .Filter("department ne null"); // .Filter("NOT(department eq null)") should also work

var usersPage = await request.GetAsync();

Resources:

Advanced queries

User properties

Upvotes: 2

Related Questions