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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / selecting items from t...
Power Apps
Unanswered

selecting items from two different tables

(0) ShareShare
ReportReport
Posted on by 29

Hi all,

 

Right now i have one Combo box with one selected item which is an employee and two tables where you can choose company and in the other table you can choose department. I have already made one with only "company" as a table, but when i try to filter with the two different tables i just cant get the formula to work. 

 

ForAll(List_Company.SelectedItems.'Company Name',
Patch('Utility_Sec.Company',
Defaults('Utility_Sec.Company'),

{
UserPrincipal:Combo_User_Comp.Selected.UserPrincipalName,
Name:Combo_User_Comp.Selected.DisplayName,
Company:'Company Name'
}
)

 

this is the code for "company" only and it works

 

ForAll(List_Company_Dept.SelectedItems.'Company Name',
Patch('Utility_Sec.Department',
Defaults('Utility_Sec.Department'),
{
SecurityUserPrincipal:Combo_User_Dept.Selected.UserPrincipalName,
Name:Combo_User_Dept.Selected.DisplayName,
Company:'Company Name'
}
)
);
ForAll(List_Department.SelectedItems.'Department Code',
Patch('Utility_Sec.Department',
Defaults('Utility_Sec.Department'),
{
DepartmentCode:'Department Code'
}
)
)

 

and this is the code i tried for "company" + "department" any suggestions how i get it to work?

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,051 Most Valuable Professional on at

    Hi @NicoPet ,

    Ou do not need to repeat 'Company Name', but your structure is correct - do you get any errors or does it simply not work

    ForAll(
     List_Company.SelectedItems,
     Patch(
     'Utility_Sec.Company',
     Defaults('Utility_Sec.Company'),
     {
     UserPrincipal:Combo_User_Comp.Selected.UserPrincipalName,
     Name:Combo_User_Comp.Selected.DisplayName,
     Company:'Company Name'
     }
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • NicoPet Profile Picture
    29 on at

    <When i try to do a preview to see if it works the different components of the app works. I can choose a user, i can choose the company and i can choose which department to add the person to but it just simply wont work when i press 'add selected' afterwards

     

    Sometimes in the code it comes up with the message Department code: Field 'DepartmentCode' is required

     

  • WarrenBelz Profile Picture
    153,051 Most Valuable Professional on at

    Hi @NicoPet ,

    I suspect Department Code is a required field, which is not included in the first Patch.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • NicoPet Profile Picture
    29 on at

    Yes it underlines in the first part of the code.

     

    But what exactly would it look like if i want to add the required field. I am very much a new user of PowerApps and writing code in a whole 

     

    Ty for taking your time to answer

  • WarrenBelz Profile Picture
    153,051 Most Valuable Professional on at

    Hi @NicoPet ,

    You need to Patch it into any code creating a new record - also because it has the same name, you neeed to do this.

    ForAll(
     List_Company.SelectedItems As aPatch,
     Patch(
     'Utility_Sec.Company',
     Defaults('Utility_Sec.Company'),
     {
     'Department Code':aPatch.'Department Code',
     UserPrincipal:Combo_User_Comp.Selected.UserPrincipalName,
     Name:Combo_User_Comp.Selected.DisplayName,
     Company:aPatch.'Company Name'
     }
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

     

  • WarrenBelz Profile Picture
    153,051 Most Valuable Professional on at

    Hi @NicoPet ,

    Just checking if you got the result you were looking for on this thread. Happy to help further if not.

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • NicoPet Profile Picture
    29 on at

    @WarrenBelz 

     

    Hello again

     

    Thanks for being patient with me 🙂 So i tried to insert the input you gave me but unfortunately it still wont accept it.  This is how it looks for me right now:

    NicoPet_0-1646827932769.png

    Can you tell from this picture what i am missing? also, is it possible to not repeat the "Forall" function and instead write it combined?

     

    NicoPet_1-1646828595730.png

     

    For reference "Combo-User-Dept" refers to the dropdown menu on the left hand side. "List_Company-Dept" is the left one of the two tables on the right side of the screen and "List_Department" is the right 

     

  • WarrenBelz Profile Picture
    153,051 Most Valuable Professional on at

    Hi @NicoPet ,

    If List_Company_Department is a Gallery, it would only have one selected item ? Also what is the Items (in Text please) of User_Combo_Comp as that seems to be your error.

  • NicoPet Profile Picture
    29 on at

    @WarrenBelz 

     

    Both List_Company_Dept and List_Department is a list box and the reason they right now only are holding "all" is because the contents of them is being controlled by someone else and they accidently wiped them, but normally in List_Company_Dept there are around 17 different companies to choose from and List_Department is an even longer list of all departments.  

     

    Behind the two tables is a box where the selected items get thrown into and from that box you can see which companies and departments the user has access to but you can also remove them again with the button below "remove access" (if it worked ofc)

     

    NicoPet_0-1647178923745.png

    Here you can see the box in the middle i described above. the blue marked area is a company i could have access and choose to remove again if i wanted

     

    As for combo_user_comp_i changed it to combo_user_dept as thats the name of the combo box. 

    The text says: Office365Users.SearchUser({searchTerm:Search_User_Dept.Text})

  • WarrenBelz Profile Picture
    153,051 Most Valuable Professional on at

    Hi @NicoPet ,

    If you put 

    Combo_User_Comp.Selected.UserPrincipalName

    on a label, do you see the value you expect? Also what does the error say is wrong?

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard