web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Automate
Answered

Search for job title

(0) ShareShare
ReportReport
Posted on by 1,934 Moderator

Is it possible to search for a user's email based on his job title? I'm using Search for users (V2). It works fine when you use the person's name, but searching for Director returns [].

 

Thanks,

Anne

Categories:
I have the same question (0)
  • Krzysztof Borkowski Profile Picture
    Microsoft Employee on at

    Office 365 Users - Connectors | Microsoft Docs  Search string (applies to: display name, given name, surname, mail, mail nickname and user principal name). If not provided then no filtering will be applied.
    Looks like it does not search for job title but you can always apply a filter array on the result of Search.

    filterarraydirector.png

  • Expiscornovus Profile Picture
    33,874 Most Valuable Professional on at

    Hi @annetoal,

     

    In addition to @Kristóf's nice solution you could also use the List Users method of the Graph API with a $filter.

     

    In this example I am using the Invoke an HTTP Request action from a premium connector btw.

     

    jobtitle_director_graph.png

  • annetoal Profile Picture
    1,934 Moderator on at

    Are you saying to filter the output of Search for users? I am trying to avoid searching for a user's name. I want to search on the job title, not the name, to avoid having to change the code every time the job changes personnel. I already know the user's name and the job title--I'm just trying to let Flow get the email address corresponding to a job title without having to hard-code personnel data into the Flow.

     

    Thanks,

    Anne

  • annetoal Profile Picture
    1,934 Moderator on at

    Thanks, but I don't have access to Premium connectors.

     

    Anne

  • Verified answer
    Expiscornovus Profile Picture
    33,874 Most Valuable Professional on at

    Hi @annetoal,

     

    In that case try the Send an HTTP request (preview) action from the Office 365 Groups connector. That one is still not premium 😁

     

    The URI is slightly different compared to my previous example. I have added a forward slash between users and ?, because of an issue @VictorIvanidze found in this thread:

    https://powerusers.microsoft.com/t5/Building-Flows/Power-Automate-O365-Groups-activities-Get-group-ID/m-p/1368027/highlight/true#M154400

     

    https://graph.microsoft.com/v1.0/users/?$select=userprincipalName,displayName,mail,jobTitle&$filter=jobTitle eq 'Director'

     

    differenturi_o365groups.png

  • Krzysztof Borkowski Profile Picture
    Microsoft Employee on at

    Hi @annetoal Yes, if you filter the output of the search users v2 array for Job Title = Director you should get a list of Directors with corresponding email addreesses. If there is only one Director instead of a Board of Directors titled Director in your AAD tenant. I might have missunderstood your use case of this Search, since you wrote tht you already know tha user's name and job title, so you can search for that name as a variable to retrieve the e-mail addresses for each of the directors who have the same name and job title.


    You can output the director's mail address to another action: In this case I used a simple compose you output the results:
    filterarraydirectorcompose.png

    Nr of users return by the empty search: length(outputs('Search_for_users_(V2)')?['body/value'])

    Nr of users who have the job title Director: length(body('Filter_array'))

    Email adress of the first Director: first(body('Filter_array'))?['Mail']


    You can always double check in your AAD if Job Title a Mail is provided: Users - Microsoft Azure 

     

    filterarraydirectoraad.png

  • annetoal Profile Picture
    1,934 Moderator on at

    I understand that I can search for a Director's name, e.g. John Smith is a Director so searching for his name gives me a Director in the Job Title. But what I want to do is make the Flow able to survive changes in personnel. So if John Smith leaves the organization, and the Flow is searching on his name, then it starts returning a null.

    But what I want is to search on a Title, and return the email address of that title. Because if John leaves the organization, another example, Mary Doe will replace him as Director. So after the personnel change, the Flow would start to return Mary's email address instead of a null. That way I protect the Flow from failure everytime there's a staff change.

    You're telling me that you can't input a Title into the search parameter, so that's out. It looks like @Expiscornovus has a solution but unfortunately it's unavailable to me. So it's looking like I am going to have to hard-code an individual name into the search 😞 Oh Well...

     

    If you think of a better way, please let me know.

    Thanks,

    Anne

  • Krzysztof Borkowski Profile Picture
    Microsoft Employee on at

    If your goal is to get the Director, and there is only 1 director in your company with a Job Title = Director, you don't care about his/her name. The empty search will return every employees and the filter will list your only those/that Employee who owns the current Job Title. You can than return his/her name, nickname, email, upn, phone nr whatever you want. It will be John, and when John leaves or change his position and the new Director will be Mary the flow will return Mary. You can also create a recurrance trigger that will check daily who is currently the director, if there will be noone you can send and e-mail to your HR group to hire one 🙂

  • annetoal Profile Picture
    1,934 Moderator on at

    Thanks for explaining the behavior of the search function. I will give it a try and post what happens.

     

    a

  • annetoal Profile Picture
    1,934 Moderator on at

    @Expiscornovus That works. Thank you so much. Incidentally, I found I could use the Premium connector, but I am afraid I still don't have some access right, because using it produced the error

     

    Access token validation failure. Invalid audience.

     

    But using the non-Premium connector you mentioned worked and produced the output I needed. Thanks again.

     

    Anne

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 959

#2
Valantis Profile Picture

Valantis 872

#3
Haque Profile Picture

Haque 589

Last 30 days Overall leaderboard