I have a button in a powerApps application that attempts to write data about selections (clients in this case) in a table for given users who've been selected. I can select multiple users and select multiple clients. when they are selected they end up in a collection (appropriately named selectedClients, and SelectedUsers) with some supplemental information. I want the code to first check and see if the client/User combo already exists in the table, and if not, then write it to the table. Currently, the formula looks like this:
ForAll(SelectedClients,
ForAll(selectedUsers,
If(LookUp('[dbo].[ClientAssignment]_2', UserPrincipalName in ADUserEmail ||
SelectedClient in ClientNameAssigned,"OK") <> "OK", Patch('[dbo].
[ClientAssignment]_2',Defaults('[dbo].[ClientAssignment]_2'),
{ADUserEmail:UserPrincipalName},{Priority:1},{AddedDate:Today()},
{ClientNumberAssigned:SelectedClientNumber},
{ClientNameAssigned:SelectedClient}))));
it works fine without the nested if(lookup))
piece it just writes an entry even if one already exists, which I need to avoid. running this code currently produces strange results that I can't really even find a pattern to. I wonder if it's my nesting, or if it's how the ForAlls function (I read in the documentation that delegation is an issue, and I don't know enough about what that means, but I understood it to be the order in which it checks the individual items in the loop). Also it could be just something small, as you all know what it's like to get nested deeper and deeper inside a formula, it's like a black hole of confusion.
Any insight would be appreciated! let me know if I need to add more information.
Aucun commentaire:
Enregistrer un commentaire