0

How can write logic in REST API if current user login is from department XX-YYZ-AB or ZZ-YYZ and I have another list with list of people with different departments, so how shall I exclude users in my REST call so if I am from XX-YYZ-AB shall exclude all users who fall under XX-YY same goes for if my login department is ZZ-YYZ it exclude all user in my REST call who falls under ZZ-YY.

for ex

Login User Dept AA-XXV

And other users department

AA-XXV

AA-XXV-GG

AA-XX

AA

So it should only show AA after filter in rest api is it possible other should exclude ?

3
  • are you able to get the user department?
    – Saira
    May 16 at 2:21
  • yes i can get department
    – Ashok
    May 16 at 8:48
  • Please mark the question as answered if it has answered your question
    – Saira
    May 17 at 22:24

1 Answer 1

1

You can achieve the results using two API calls.

I have created a 'TestDL' list having 'TestPerson' column of type Person. You need to use two rest API

  1. first API to get the department of logged in user. Suppose the logged in User Department is IT
  2. Call another API and pass the Department name that you got in 1st API call.

https://site_url/_api/web/lists/getByTitle('TestDL')/items?$select=TestPerson/Title,TestPerson/EMail,TestPerson/Department&$expand=TestPerson&$filter=TestPerson/Department eq 'IT'

It will give you result of people 'TestPerson' column who are in IT depatment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.