cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sfishe
Level: Powered On

Pass table, or table name, via context variable for use with Remove()

I'm trying to create a shared use/dynamic "confirm delete" screen - so one that is navigated to from every delete button in the app, and context variables passed via Navigate provide the table and item to delete.

 

An example delete button has: 

OnSelect = Navigate(DeleteConfirm,ScreenTransition.Fade,{TableToDelFrom:'Exp Behaviour 2', ItemToDel:Gallery_Behaviour.Selected, DelReturnScreen:'Home Screen'})

 

On the DeleteConfirm screen, the "Yes" button has:

Remove(TableToDelFrom,ItemToDel); Navigate(DelReturnScreen,ScreenTransition.Fade)

 

All of the context vars appear to be accepted by PowerApps except the 'TableToDelFrom' var. The error given on this var is: "The first argument of Remove should be a collection". Also, the Remove function fails.

 

Is there a better way to do this? Or how else can I reference the table to delete in a case like this?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
sfishe
Level: Powered On

Re: Pass table, or table name, via context variable for use with Remove()

Thanks guys for all the help!

 

I ended up going with a mix of solutions - using a seperate screen still and just passing the table name as a string, and have a hardcoded If() statement with my tables to target the correct one. I only have 5 tables so it isn't too bad.

 

 

View solution in original post

4 REPLIES 4
Community Support Team
Community Support Team

Re: Pass table, or table name, via context variable for use with Remove()

Hi @sfishe,

 

 

 

I think the issue here should be the Remove function can't accept the Table Variable as an available Collection (or a data source).

For the error message, we could workaround with clearcollect () function.

 

Remove(clearCollect(TabletoRemove, TableToDelFrom),ItemtoDel)

 

But the issue is, the formula above would only work with the collection, not the data source. So doing this won't delete the record from the data source.

 

Workaround should be:

1. under the Remove button, clear the remove formula, instead, using the following formula to configure the variable under onSelect Property:

 

UpdateContext({ConfirmDel:true})

  Then set its Visible property to:

 

 

If(ConfirmDel,false,true)

2. Add another button, change its text property to confirm delete, then modify the OnSelect property of the button with the formula below:

 

  

Remove(DataSource, BrowseGallery1.Selected); 
If (IsEmpty(Errors(DataSource, BrowseGallery1.Selected)), Back());
UpdateContext({ConfirmDel:false})

then modify the Visible property to:

ConfirmDel

Doing it in this way would require the user to double click to delete a record.

 

Hope it helps.

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
mr-dang
Level 10

Re: Pass table, or table name, via context variable for use with Remove()

I personally do not navigate to another screen to confirm a deletion. Instead, I recommend you code an animation like a pop up or fade to black to reveal a confirm/cancel dialog on the same screen.

 

I have a few tutorials here and there for these kinds of animation: 

https://drive.google.com/open?id=1p6btpICZ1CKXREWVf68X66-i2SwLDjRwfLWQVAw_98E

 

Once you set up the animation, you can create buttons to confirm or cancel.

Remove('Exp Behaviour 2',First(Filter('Exp Behaviour 2',PrimaryId=Gallery_Behaviour.Selected.PrimaryId))); 

This means, "Remove the first record in 'Exp Behaviour 2' whose PrimaryId matches the PrimaryId of the record selected in Gallery_Behaviour, where PrimaryId is just a column used as a unique identifier."

 

There are many benefits to staying on the same screen. First you do not need to mess with OnVisible/OnHidden properties triggering when you don't want it to upon returning to the same screen. There are fewer variables to define since you can reference controls and existing variables on the screen. And you do not need to mess with passing variables between screens which can be problematic if not defined correctly.

 

As an aside, I would start switching over to Set() instead of using the third argument in Navigate to pass a variable.

 

_____

 

 

If you want to maintain most of your original coding, you can just change the red parts:

Remove('Exp Behaviour 2',ItemToDel); 
Navigate(DelReturnScreen,ScreenTransition.Fade)


Or to be extra sure it works:

Remove('Exp Behaviour 2',First(Filter('Exp Behaviour 2',PrimaryId=ItemToDel.PrimaryId))); 
Navigate(DelReturnScreen,ScreenTransition.Fade)

 

This means, "Remove the first record in 'Exp Behaviour 2' whose PrimaryId matches the PrimaryId of ItemToDel."

 

 

Microsoft Employee
@8bitclassroom
Meneghino
Level 10

Re: Pass table, or table name, via context variable for use with Remove()

Hi @sfishe

I fully agree with @mr-dang that his approach is also good and avoids the OnVisible/OnHidden issues.

Personally, I don't use pop-ups because there is no easy way of doing them in PowerApps and a separate screen approach seems cleaner in a way.

I basically pass two context variables to the delete confirmation screen, one is the table ID (just an integer) and the other the item ID, then the delete statement chooses the table with if statements.

If(
TableID = 1, RemoveIf(MyFirstTable, ID=ItemToRemoveID),
TableID = 2, RemoveIf(MySecondTable, ID=ItemToRemoveID),
etc etc.
)

If you don't have an ID column in all your tables, you will need different variables

Highlighted
sfishe
Level: Powered On

Re: Pass table, or table name, via context variable for use with Remove()

Thanks guys for all the help!

 

I ended up going with a mix of solutions - using a seperate screen still and just passing the table name as a string, and have a hardcoded If() statement with my tables to target the correct one. I only have 5 tables so it isn't too bad.

 

 

View solution in original post

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 65 members 3,471 guests
Please welcome our newest community members: