cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
powerapps890
Post Prodigy
Post Prodigy

ce andRemove item from datasource based on a dropdown

I have a dropdown in my datasource that says approve and deny. If approve is selected I want it to patch to a new datasource with identical columns. If it is denied then I want it to be removed from one data source and the field updated to denied in another. If(Dropdown.selected = "Approve", Patch....), Remove('List1', Filter('List1', 'Created By'.Email = varUserEmail && Title) && Remove('List2', Filter('List2', 'Created By'.Email = varUserEmail && Title)). Would something like this work? I just need a patch for approve and two removals based on the persons name and title. 

1 ACCEPTED SOLUTION

Accepted Solutions
v-albai-msft
Microsoft
Microsoft

Hi @powerapps890 ,

What do you mean "based on Title"? I can't understand this condition in your formula: "'Created By'.Email = varUserEmail && Title". Why does a Title appear here(maybe you forget to add condition for Title column)? Does this formula contain two conditions?

I think the key of your issue is that: for adding more actions in a false case of an if(), you should use “;” instead “&&”.

I assume your varUserEmail is a variable set by Set(), and I do a test in my side. You can refer to my steps:

1. Create two lists called "list1" and "list2". List1 has a DropDown column called “dropdown1”, list2 has a Text column called “dropdown1”. Then create an app based on list1.

v-albai-msft_0-1611570289391.png

v-albai-msft_1-1611570289394.png

2. Set OnStart property of App to below(this is the email of “allen bai”):

Set(varUserEmail,User().Email)

v-albai-msft_2-1611570289397.png

3. For test, go to Edit Screen(based on your requirement, you can set this formula in other screen), set the OnChange property of the Submit button from “SubmitForm(EditForm1)” to below(the name of my Title control is DataCardValue3, the name of my dropdown1 control is DataCardValue6):

If(DataCardValue6.Selected.Value="approve",Patch(list2,Defaults(list2),{Title:DataCardValue3.Text,dropdown1:DataCardValue6.Selected.Value}),Remove(list1,Filter(list1, 'Created By'.Email = varUserEmail && Title="test2"));Remove(list2,Filter(list2, 'Created By'.Email = varUserEmail && Title="test2")));SubmitForm(EditForm1)

v-albai-msft_4-1611570289406.png

Below is result.

First selecting approve, then click submit, It patch a new record in list2, and no change to list1:

v-albai-msft_5-1611570289408.png

v-albai-msft_6-1611570289409.png

Second, select deny, after clicking submit, the item which “Title= “test2” and created by “allenbai”” is deleted:

v-albai-msft_7-1611570289410.png

v-albai-msft_8-1611570289411.png

v-albai-msft_9-1611570289412.png

Of course. above is just a simple demo, you need to edit the formula to meet your requirement.

Best Regards,

Allen

View solution in original post

6 REPLIES 6
timl
Super User III
Super User III

Hi @powerapps890 

I see no reason why that wouldn't work. You might need to fine tune the formula you use, but I think what you suggest is technically sound.

I am not sure about the syntax of this. How do I remove an item from a list based on dropdown selection ? @timl 

timl
Super User III
Super User III

Hi @powerapps890 

I'm guessing that you understand the usage of the Remove and RemoveIf functions, so the issue is working out the syntax to refer to the item that you want to delete.

https://docs.microsoft.com/en-gb/powerapps/maker/canvas-apps/functions/function-remove-removeif

If the dropdown that shows Approve/Denied is bound to a data source, you've added this to a form or gallery control, you should be able to use ThisItem to refer to the email address of the record. It would look something along the lines of this:

RemoveIf('List1', 
         'Created By'.Email = ThisItem.'Created By'.Email
)

 

 

v-albai-msft
Microsoft
Microsoft

Hi @powerapps890 ,

What do you mean "based on Title"? I can't understand this condition in your formula: "'Created By'.Email = varUserEmail && Title". Why does a Title appear here(maybe you forget to add condition for Title column)? Does this formula contain two conditions?

I think the key of your issue is that: for adding more actions in a false case of an if(), you should use “;” instead “&&”.

I assume your varUserEmail is a variable set by Set(), and I do a test in my side. You can refer to my steps:

1. Create two lists called "list1" and "list2". List1 has a DropDown column called “dropdown1”, list2 has a Text column called “dropdown1”. Then create an app based on list1.

v-albai-msft_0-1611570289391.png

v-albai-msft_1-1611570289394.png

2. Set OnStart property of App to below(this is the email of “allen bai”):

Set(varUserEmail,User().Email)

v-albai-msft_2-1611570289397.png

3. For test, go to Edit Screen(based on your requirement, you can set this formula in other screen), set the OnChange property of the Submit button from “SubmitForm(EditForm1)” to below(the name of my Title control is DataCardValue3, the name of my dropdown1 control is DataCardValue6):

If(DataCardValue6.Selected.Value="approve",Patch(list2,Defaults(list2),{Title:DataCardValue3.Text,dropdown1:DataCardValue6.Selected.Value}),Remove(list1,Filter(list1, 'Created By'.Email = varUserEmail && Title="test2"));Remove(list2,Filter(list2, 'Created By'.Email = varUserEmail && Title="test2")));SubmitForm(EditForm1)

v-albai-msft_4-1611570289406.png

Below is result.

First selecting approve, then click submit, It patch a new record in list2, and no change to list1:

v-albai-msft_5-1611570289408.png

v-albai-msft_6-1611570289409.png

Second, select deny, after clicking submit, the item which “Title= “test2” and created by “allenbai”” is deleted:

v-albai-msft_7-1611570289410.png

v-albai-msft_8-1611570289411.png

v-albai-msft_9-1611570289412.png

Of course. above is just a simple demo, you need to edit the formula to meet your requirement.

Best Regards,

Allen

View solution in original post

so you put in "test2" specifically but how do I remove the record that was selected specifically? It is tagged with an ID so I think I could use that. @v-albai-msft  I don't what to hardcode for the title. 

This removes all the records in the list. I need it to remove a specific record based on ID.

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (44,959)