cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper I
Helper I

Get Email Address from SharePoint List based on Department

I have 2 Sharepoint Lists.  

List1 - Item list with one of the columns for each item being (OwningDepartment)

List 2 - 2 Columns (Department)(DeptManager)

(OwningDepartment)(Department) have a 1 to 1 relationship theoretically but are not programed as a lookup in sharepoint.

 

When a new item is created I am trying to have flow look up the Department Manager in List2 based on what OwningDepartment is selected in List1 and send them an email.

 

Can anyone help with this???

 

Thanks

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Advocate I
Advocate I

Re: Get Email Address from SharePoint List based on Department

Hi @Teaners26,

 

 

Let's see what we can do.

 

I have my two lists.

List 1

List1-MakingAnItem.PNG

 

And List 2

 

DepartmentList-List2.PNG

 

  1. First you're going to create a trigger "When an item is created".  You're going to point this at your list 1,as you said.

    WhenAnItemIsCreated.PNG

  2. Create a "Get items" action and point it at your second list.  This is where the magic happens.  In the advanced options section, under filter query, you are going to create the filter. Your filter is going to look at items with a department value that equals the department value of the newly created item. 

    GetItemsAndFilter.PNG

    My filter query looked like this: 

    Dept_x0020_Manager eq '[Department Value]'


    There are three parts to this: 
    1. Dept_x0020_Manager - This is official name of your column in List 2 that you would like to search for a matching department name.
    2. eq - This is saying to look for things that have [value1] that equal [value2].
    3. '[Department Value]' - this returns the department value from the item that initiated the flow in List 1.  

    To find your column name (mine above was Dept_x0020_Manager), go to the list settings in List 2 and click on your "Dept Manager" column.  Then look at the end of your URL and you'll see it following "Field=".

    GoToListSettingsAndColumnSettings.PNG


    ColumnName.PNG


  3. Then create your email and fill in your variables. 

    You don't need to create the "Apply to each" piece.  It isn't necessary in this case but because our output was from a "Get items" action it could theoretically return multiple items, therefore when I created the next step, it created the "apply to each" loop.  This won't affect anything -- if there is only one item returned, it will only run once.

    SendEmailAboutNewItem.PNG

Let me know if this helps!

 

-Stuart

View solution in original post

Highlighted
Helper I
Helper I

Re: Get Email Address from SharePoint List based on Department

I got this to work but i had to switch Dept_x0020_Manager with Department in the below expression.

 

Dept_x0020_Manager eq '[Department Value]'

View solution in original post

13 REPLIES 13
Highlighted
Advocate I
Advocate I

Re: Get Email Address from SharePoint List based on Department

Hi @Teaners26,

 

 

Let's see what we can do.

 

I have my two lists.

List 1

List1-MakingAnItem.PNG

 

And List 2

 

DepartmentList-List2.PNG

 

  1. First you're going to create a trigger "When an item is created".  You're going to point this at your list 1,as you said.

    WhenAnItemIsCreated.PNG

  2. Create a "Get items" action and point it at your second list.  This is where the magic happens.  In the advanced options section, under filter query, you are going to create the filter. Your filter is going to look at items with a department value that equals the department value of the newly created item. 

    GetItemsAndFilter.PNG

    My filter query looked like this: 

    Dept_x0020_Manager eq '[Department Value]'


    There are three parts to this: 
    1. Dept_x0020_Manager - This is official name of your column in List 2 that you would like to search for a matching department name.
    2. eq - This is saying to look for things that have [value1] that equal [value2].
    3. '[Department Value]' - this returns the department value from the item that initiated the flow in List 1.  

    To find your column name (mine above was Dept_x0020_Manager), go to the list settings in List 2 and click on your "Dept Manager" column.  Then look at the end of your URL and you'll see it following "Field=".

    GoToListSettingsAndColumnSettings.PNG


    ColumnName.PNG


  3. Then create your email and fill in your variables. 

    You don't need to create the "Apply to each" piece.  It isn't necessary in this case but because our output was from a "Get items" action it could theoretically return multiple items, therefore when I created the next step, it created the "apply to each" loop.  This won't affect anything -- if there is only one item returned, it will only run once.

    SendEmailAboutNewItem.PNG

Let me know if this helps!

 

-Stuart

View solution in original post

Highlighted
Helper I
Helper I

Re: Get Email Address from SharePoint List based on Department

I got this to work but i had to switch Dept_x0020_Manager with Department in the below expression.

 

Dept_x0020_Manager eq '[Department Value]'

View solution in original post

Highlighted
Advocate I
Advocate I

Re: Get Email Address from SharePoint List based on Department

I'm glad you got it working!  

 

 

Highlighted
Advocate I
Advocate I

Re: Get Email Address from SharePoint List based on Department

You're right about substituting Department for Department_x0020_Manager in the filter query. That was an error.

 

I can't remember if I tested my solution -- I probably didn't.

Highlighted
New Member

Re: Get Email Address from SharePoint List based on Department

@m4ngo5 I have a nearly identical scenario except my analagous "Department" column in List 1 is a multiple selection lookup column of the department column of List 2. I want separate emails to be sent to each designated person.

 

I tried adding a For Each block to try to get it to run for each "Department" selected but it doesn't seem to be working

 

Do you know if/how I can modify the method you showed to my needs?

 

I know sharepoint isn't super friendly to lookup columns or multiple selections. 

 

Thanks!

Highlighted
Advocate I
Advocate I

Re: Get Email Address from SharePoint List based on Department

@zz6If you still need help on this, I think I have the answer for you. 

 

When you have a list or library with lookup columns and you want an ODATA filter query to use these lookup columns, there is a special syntax for it.  You need to type in the name of the primary lookup column, a forward slash, then the name of the project lookup column (the child column). 

 

Here is a screenshot of one of my Flows.  The SharePoint library has a lookup column for Project Number, and a projected column for the Status which comes from the lookup against the Project Number list.  Syntax is ParentColumn/ChildColumn.

 

FlowScreenshot.png

 

If that's not what you're looking for, tag me and let me know!

Highlighted
Helper I
Helper I

Re: Get Email Address from SharePoint List based on Department

Hi @m4ngo5 ,

 

why the filter query is not :

Department (in List2) eq '[Department Value]' (in list1)?

Thank you.

Highlighted
Advocate I
Advocate I

Re: Get Email Address from SharePoint List based on Department

Hi @walking,

 

I'm a little confused, but I'll do my best to answer.  It looks like you may be pointing out that I did not answer @zz6 properly, so thank you for that.  I didn't address the case of filter queries directed at the primary lookup column, I addressed only the case of filter queries directed to child lookup columns.  For the primary lookup column, the syntax is the same as the child lookup columns, except you use a forward slash with title.  The syntax for my previous example would be:

 

ProjectNumber/title eq '[Value]'

 

And for the department example from @zz6, it would be:

 

Department/title eq '[Department Value]'

 

I tested that this works against lookup columns with multiple selection enabled.  If the filtered value is contained in the lookup column, the record will be returned.

 

You can filter for records that match both of two values in the department column by connecting two filter queries with an "and".  Likewise, an "or" substituted for "and" will filter for records that match either of two values. 

 

Building on this, you could use a for loop to append multiple filter queries to a string variable, and insert this string variable into the filter query field. This could be used to created a dynamic filter query that returns records that match a long list of values -- perhaps values which are not known until the flow runs.

Highlighted
Frequent Visitor

Re: Get Email Address from SharePoint List based on Department

@m4ngo5 

 

I'm really struggling to get my head around this. When I tried the first solution above I was told my column doesn't exist.

 

Essentially, I have a form that when filled out plugs the data into a sharepoint list. I have already been able to create a lookup as part of this flow, that identifies the submitters region, based on their country in O365.

 

As part of this I want an email to go to specific set of people based on region and job role. This is in another list in a matrix. Ideally, it would be good to keep the people for each region and role separate for ease of updating should someone leave or be replaced (me included).

 

The main list (list1) looks like this in essence (many other column besides):

list1.png

The contact list looks as follows (List2):

list2.png

 

Now I am creating an additional flow that looks for a new item being created in List 1. It should then look up the region in the title column of List 2, and add send to the email addresses of each person in each job role for that region. The job roles are people or contact fields, where the flow picks up the email address from the O365 contact. In testing I've not filled out the other fields yet other than one with my own person in.

 

My flow looks like below:

flow1.png

Now, when this flow is run, it fails with the message "Column NWE does not exist", and after batting my head against this for a few days, I cannot understand why...

 

results1.png

 

It's clearly picked something up from somewhere, but I am at a loss. I'd be very grateful for any support given by anyone!

Highlighted
Advocate I
Advocate I

Re: Get Email Address from SharePoint List based on Department

@Dewi86If I understand this correctly, when an item is created in List 1, you want to notify a list of individuals from that region that this new item has been created.  So if the item in List 1 has a region of NWE, in List 2 there is an entry for the NWE region with columns that include the people you want to email including the Regional ISSO, IT Lead, Legal Rep, etc.

 

I'm noticing a few things that could be wrong:

  • Shouldn't Get Items be operating on List 2, not List 1?
  • You probably need single quotes around 'Region' in the filter query.
  • If Region in List 1 is a lookup column, there should be a column called 'Region Value' that you will probably need to use for your filter query instead of 'Region'

 

Please let me know if that helps!

Highlighted
Frequent Visitor

Re: Get Email Address from SharePoint List based on Department

Hi @m4ngo5 ,

 

Thanks for coming back to me so quickly!

 

I've looked over it and:

 

  • Get Items is List 2, mistake in my image
  • I added the quotes, no change
  • The Region column in list 1 is just a single line of text. Does this need to be a lookup column? I guess that would make sense, unless there is an alternate method I'll redo the flow used for the form data capture.
Highlighted
Anonymous
Not applicable

Re: Get Email Address from SharePoint List based on Department

Hi, 

 

I have currently experiencing a similar situation which I want to resolve. I am trying to make a flow which triggers an email to Department Managers as well as their respective team members when an issue item has been created on sharepoint.

 

I have 2 sharepoint list: Test HPBC Sunset v2 consisting of 4 columns: Title, Raised By, Private or Public, Description, Request Date, Department and Department:Manager. I have the created another list called Department Managers which consists of Department, Manager (email address) and Team Member (email addresses of team members).  

 

Ideally, whenever I create another item on HPVC Sunset v2, it would trigger an email to the Department Manager and Team Members of the Department that the user has inputted. For example, for the Test 2 item, the flow would trigger an email to the Finance Manager and Finance Team Members when the item is added. However, currently, whenever an item is created in HPVC Sunset v2, emails are generated to all team members and managers that are listed in Department Manager, instead of to repective team members and manager of the newly added item. 

 

Any help on this would be very much appreciated 🙂

3.2.jpg4.2.jpg

Highlighted
Helper II
Helper II

Re: Get Email Address from SharePoint List based on Department

Hello @m4ngo5 ,

 

I am new with Flows.

 

Considering the same example with your List 1 and List 2 (Deparment managers and Item with department).

Suppose i want a condition that, when a new item is created in List 2 , the particular item ID in list 2 should be equal to item ID in list 1 (for newly created only). After that send an email when the condition satifies for the new item.

Could you help me to create MS flow out of this because what happens is in my flow is, it looks for all IDs not the new ID and send me multiple emails, as all IDs are same in List 1 and List 2 so the condition satifies for all items.

 

If possible please reply fast.

 

Thanks in advance.

 

Reagrds,

Sanket

 

 

Helpful resources

Announcements
firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Users online (6,245)