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

Community site session details

Session Id :
Power Apps - Building Power Apps
Suggested answer

Prevent a duplicite

(0) ShareShare
ReportReport
Posted on by 78
Hello, I have two galleries, in one is selected a user who has assigned somee tasks in gallery 2. These are assigned through a form where is a choice dropdown for the tasks. I need to backstop when someone tries to add a user a task which is already assigned. How can I do this? Thanks.
I have the same question (0)
  • TSte Profile Picture
    208 on at
    Prevent a duplicite
    I assume the List of Tasks will have a "assigned to" column, the dropdown should be filter for items where "assigned to" is blank..
     
    Filter(taskslist,IsBlank("assigned to" column))
  • Suggested answer
    CU05110754-0 Profile Picture
    4,982 Super User 2025 Season 2 on at
    Prevent a duplicite
    Hey,
     
    So I would assume you have in your datasource a column taht saves some sort of ID to link the task to the User.
    So you could just put the Record in a local Variable (if you stay n the same screen otherwise global variable) and say that it has to be different. 
    Filter(UserDatasource, UserID <> VarTask.UserID)
    If this solvede your porblem please accept it as solution so others can find it as well. 
    If it helped in any other way consider liking it so we can keep supporting eachother. 
  • JM-14081323-0 Profile Picture
    78 on at
    Prevent a duplicite
    I believe I cant do that either way, because the tasks are stable and are assigned to a lot of the users (i am using submit form to save it for the relevant user). When there are some new users to the first gallery, they will also be assigned with some of these tasks.
  • JM-14081323-0 Profile Picture
    78 on at
    Prevent a duplicite
    My dataverse table has a column with choices (tasks) and the form creates records in it, where there is a column with user and next to it the task from the choices,.
  • JM-14081323-0 Profile Picture
    78 on at
    Prevent a duplicite
    I imagine I can use a combobox with Relate instead of a form but the form allowes me to put there a text input with a name of who has assigned he tasks to the user. Could I that in combination with a combobox?
  • RyanAutomates Profile Picture
    139 on at
    Prevent a duplicite
    Hi there,
     
    I don't know if the following will solve your solution, as I don't think I'm clearly understanding your data model. Do you want to achieve 1 Task = 1 User and a Task can only ever have 1 User? In your original post you've said you don't want to assign a User to a Task that's already assigned, but in your comments below you say "because the tasks are stable and are assigned to a lot of the users"? Can you clarify please?
     
    For 1 Task = 1 User
    In your solution, you could add a "Status Reason" option to your task called something like "Assigned", then create a view called something like "Assigned Tasks". 
     
    You can then make your gallery filter on this view.
     
    You could either use Power Fx to patch the statuscode to this option "Assigned" when the button is used to assign it, or depending on your data model - I assume you have a lookup field on the Task to User for an N:1 relationship, or ideally, you are using the "Owner" (owninguser) column - you could add a classic workflow that runs on Task, and on change of that lookup field that runs in real time, to set that Status Reason to "Assigned", which should immediately filter it out of the gallery view.
     
     
    Hope this helps! :)
     
  • JM-14081323-0 Profile Picture
    78 on at
    Prevent a duplicite
    I am using a lookupfield task to user N:N
    Each task can be assigned to many users (if not all of them) and each user can have many tasks
    I only want to block the option to assign one task to certain user many times. So when you click on John in the 1st gallery, there will be assigned tasks 1,2,3,4 and I will not be able to duplicate (I can not assign now 1,2,3,4. I can only assign 5,6,7,8 to John). But when click on George, he only has now assigned 1 and 2, so I can assign 3,4,5,6,7,8.
     
    Thank you for advices
  • Suggested answer
    RyanAutomates Profile Picture
    139 on at
    Prevent a duplicite
    Hi there,
     
    Thanks for clearing that up.
     
    In that case, you need to query Microsoft's hidden intermediate table for that N:N relationship to find out if the User is related to that table, then do something based on it, like disable the assign button or hide the Tasks already linked to the selected User.
    This table has 3 useful fields - the 3 unique IDs for the value of Table 1, the joining ID (ID of the intermediate table) and the value of Table 2.
    This can be seen most easily (in my opinion) using SQL4CDS in the XRMToolbox, by querying that intermediate table (the name of which will be similar to the relationship name)
     
    SELECT TOP 1000 *
    FROM {Intermediate Table Name)
    WHERE 1=1
     
     
    You can filter your list of dropdown options based on Tasks that do not have a row in this table in some way like this:
     
    Filter(IntermediateTable, Table1Field != ThisItem.ID)
     
    If you want to only show records not already assigned to the selected User, I would use ClearCollect to put this into a fresh collection each time a User is selected, and then have the dropdown options show that collection, which is filtered on Tasks related to this selected user through that intermediate table, something like this:
     
    // In the OnSelect property of a button
    ClearCollect(
        RelatedTasks,
        Filter(
            Tasks,
            TaskID in Filter(Intermediate Table, UserId = UserGallery.Selected.UserID).TaskId
        )
    )
     
    Note; This solution doesn't prevent Tasks from being assigned to the same User, it just hides the possibility of happening from the UI/UX of your App with these controls.
     
     
     
    Hope this helps! :)
  • JM-14081323-0 Profile Picture
    78 on at
    Prevent a duplicite
    Thank you, that sounds very good, but...i am sorry for my low knowledge and understanding...
     
    If we leave the toolbox, which tools I am not familiar with at all, the idea is that I can create a new table in Dataverse with 1:N relationship with both "user table" and "task table", where the new table is many and in that I create three columns?
     
    Can you navigate me with setup of this table and how did you meant to put records in it?
    Many thanks

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 652 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 410 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 236

Last 30 days Overall leaderboard