How to display gallery items based on many-to-many relationship in PowerApps / Dataverse? - many-to-many

I need help with displaying gallery items based on many-to-many relationships.
Context:
So far, I built a separate canvas screen that can build a relationship between an "Employee" to many "Departments" based on this documentation: https://powerapps.microsoft.com/et-ee/blog/option-sets-and-many-to-many-relationships-for-canvas-app...
Now on another screen, my "Event" Screen, which consists of an edit form and a vertical gallery, a User (an employee) can submit an Event form (containing a single Department in a dropdown box) which is connected to the "Event" Table in Dataverse.
This is my question:
In the 'Items' of a Vertical Gallery, how do I filter such that an Employee logged in can view Events based on the Departments that belong to them.
Here's an example/scenario:
Pedro belongs to the "Finance Department" and the "Product Department"
Aiko belongs to the "Computer Eng. Department"
Suraj belongs to the "Product Department" and the "Mechanical Eng. Department"
Ahlem belongs to the "Finance Department"
This is the result I want based on the scenario above:
-What Pedro sees in his Vertical Gallery is only a list of Events that have a "Finance Department" selected value and Events that have a "Product Department" selected value.
-What Aiko sees in her Vertical Gallery is only a list of Events that have a "Computer Eng. Department" selected value.
-What Suraj sees in his Vertical Gallery is only a list of Events that have a "Product Department" selected value and Events that have a "Mechanical Eng. Department" selected value.
-What Ahlem sees in her Vertical Gallery is only a list of Events that have a "Finance Department" selected value
Dataverse Tables and columns (with data types):
Event(s)
id event (primary)
department (Lookup to single Department)
other fields/columns of this table are not important
Employee(s)
id empl (primary)
employee name (Text: Plain text)
email (Text :Email)
(Department(s) is a hidden column in Dataverse because its a many-to-many relationship )
Department(s)
id department (primary)
department name
(Employee(s) is a hidden column in Dataverse because its a many-to-many relationship )
The relationships:
Many Employees To Many Departments (Many to Many)
Many Events To One Department
Hints:
'Employee(s)'.email = User().Email

In the 'Items' of a Vertical Gallery, how do I filter such that an Employee logged in can view Events based on the Departments that belong to them.
This will be 2-3 step process.
First you will have to get Guid/UserID of loggedin user. You will have to filter systemuser Table (dynamics/dataverse Table). Note User().Email gives you Email of your Office365 user but you can easily figure out how to get logged in user Guid.
Then you will have to fetch Departments where user is part of. Take a look here
Now you got say from a list of 100 departments filtered 3-4 departments where logged in user is part of.
Once you have department you can easily get events a event and Department are 1-N or N-1 relationship. Here you can filter based on lookup filed.
Note: At later stage you might want to consider/think about Delegation.
Delegation is restriction if you have for example more than 2K records Powerapps will only perform all the operation on first 2k records. It will not give you correct result.

Related

Access: Combo box and many-to-many relationship

I am fairly new to MS Access and looking for a solution regarding a form I am trying to build. The form should be used to show different user entries and to create or modify users.
The problem I am blocking is for a combo box and a many-to-many relationship.
I have several tables which combined provide me the information I use to build the form.
My first table Users provides me information about *first name, last name etc. *
A second table Servers includes the list of different country servers a user can have access to.
Since an user can have access to different servers/countries and a country/server can have different users I am confronted with a many-to-many relationship. Therefore I created a junction table which includes the userID as FK (from the User table) and the ID as FK (of the country/server from the Servers table).
What I am trying to achieve now but where I am blocking is:
to have a combobox which lists all available servers/countries
mark the entries which are linked to the user record which is shown
e.g.
Servers: Belgium, Germany, Netherlands, Sweden, UK
User: John Doe => access to Germany & UK
list/combobox should show all countries but select only the ones John doe has access to (when record John Doe is selected)
Is there any way to achieve this and what needs to be done ?
I am also open for any other solution if this cannot be done via a combobox.
Thanks for the help.

Only show data from chosen option from previous column in a lookup field

I have a three tables - for simplicity let's call them - meat, dish, and order. In the meat table, there are different types of meat; in the dish table, there are different types of dishes you can prepare with those types of meats; in the orders table, the orders for these dishes are shown. The orders table has OrderID, MeatID, DishID.
I'm trying to make it so in the Design View on Microsoft Access when the drop menu displays all the types of meat in the MeatID column and chooses one, the other drop down menu in the DishID column will only display the types of dishes in relation with the meat
If so, is there a way to make Access automatically know using this code:
SELECT Meat.MeatName, Dish.DishName
FROM Dish
INNER JOIN Meat ON Meat.MeatID = Dish.MeatID
WHERE MeatID = [the selected meat in the previous column]
You can use the Meat combobox value as criterium, like this:
WHERE MeatID = Forms!yourFormName!cboMeat
Additionally, in the AfterUpdate event of cboMeat you need:
Me.cboDish.Requery
so it will read the dishes to the newly selected meat.
For more examples, search for: access linked combo boxes
It's a very common (and useful) technique.

Symfony 2 - create a form with a parent entity filtering the options of the child entity

I am new to symfony and PHP.
I have a problem that I hope someone can help:
supose we have 3 entities.
Groups, specialities, works; works belong to a speciality, speciality belong to a group.
Supose that I want to have a form to create a "work". I want to filter my specialities according to a select with the list of groups ( much like on a travel site where we get the destinations filtered by the origin).
So my form will only have 2 fields. The speciality and a name for the work. But in my view i must have 3 fields, 1 for groups that will filter the specialities and the fields belonging to the form.
Much like a booking flights site I must see the fields from the begining.
This as to be so simple, but I'm really stuck on it.
Thank you
At this moment I can come up with 2 solutions:
1) Use ajax.
On the request populate a selectbox with the groups. when you select one of the groups, all the specialities come into a different selectbox of that group.
2)
Use uri segments. Let the user first choose group, then go to a next page and let them choose a speciality. After that the user gets a form where he fills in the data.

How do I write this recursive MySQL procedure?

I have a MySQL database which contains 2 (relevant) tables: Staff, Supervisors.
Staff contains: StaffID, Name, CostCentre
and Supervisors contains: InstanceID, StaffID, SupervisorID, Obsolete
The Staff table contains all staff in the company, and the Supervisors table links one StaffID (StaffID) to another StaffID (SupervisorID). If we create a new relationship (i.e. staff A no longer reports to staff B, but instead to staff C), then we create a new record and set the original 'obsolete' flag to 'true'.
I have arranged it this way because the Supervisor:Subordinate relationships are subject to change, and are not guaranteed to be correct: We want to be able to change them and maintain an audit trail.
What I need to do is to get a recursive list of CostCentres.
What that means is, say I start with some cost centre. I get a list of all staff who are in that cost centre, and generate a list of all their subordinates. Then I get a list of all those cost centres and repeat for each of those.
I already have a number of procedures, two of which may be relevant:
CALL getCostCentre(iCostCentre) /* get a list of all staff in iCostCentre) */
CALL getSupervisees(iSupervisor) /* get a list of all staff who report to iSupervisor */
I would create a single table containing staff and supervisors, let's call it Employee, and another table for holding relationships (each table with a delete flag field and a change date field for audit trial). The table relationship has a subordinate and a master. And a table for cost centers holding references to the employees. There are some open source CRMs around that you can download (use it maybe) and eventually learn how to structure your db. Regarding cost centers, you can learn from the table Group in standard CRMs

Recording a many-to-one relationship in Access 2007 forms

Here's what I want to do:
The user should be able to enter a new "sale" record with some basic information (who's buying, etc.), and then add items to that sale (like a shopping cart). There's one master "Sales" table and one "SaleContents" table, that look like:
Sales: int ID, name of person buying, etc.
SaleContents: FK SaleID, Item Purchased, Quantity, etc.
How do I make a form that will allow a user to add an arbitrary number of purchased items, and then, upon saving, it:
Makes a Sale record
For each item purchased, makes a SalesContent record with a FK pointing to the above
If the user cancels, neither the Sale record nor the SalesContent record are created.
Will I have to do all of this by hand in VBA, or is there some functionality in Access to help me?
The simplest way is to use a bound form for the sale and a subform for the sales content, however, you will have to delete the record if the user cancels. It will be simpler if you allow cascade delete in the relationship between sale and sale content.
With a form / subform set-up the Link Master Field (which can also be a control) provides the value for the Link Child Field, in this case SalesID. The content ID can be provided with an autonumber.