Skip to main content

Notifications

Power Apps - Building Power Apps
Suggested answer

Prevent a duplicite

Posted on by 51
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.
  • JM-14081323-0 Profile Picture
    JM-14081323-0 51 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
  • Suggested answer
    RyanAutomates Profile Picture
    RyanAutomates 70 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
    JM-14081323-0 51 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
  • RyanAutomates Profile Picture
    RyanAutomates 70 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
    JM-14081323-0 51 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?
  • JM-14081323-0 Profile Picture
    JM-14081323-0 51 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
    JM-14081323-0 51 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.
  • Suggested answer
    DBO_DV Profile Picture
    DBO_DV 4,239 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. 
  • CU23070453-0 Profile Picture
    CU23070453-0 214 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))

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,591

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,090

Leaderboard