I have a gallery (Gallery1) drawing data from a Sharepoint (SP) list which is filtered based on user and date fields.
When an item in Gallery1 is selected (OnSelect) it alters the TemplateFill property (ThisItem.IsSelected, RGBXYZ) to highlight the item,
patches to a collection and populates fields in a form and gallery below which allow for editing of the data, these are then submitted and patched back to the SP list and Gallery1 is refreshed showing the recently made updates.
I also have an 'Add New Item' button which patches a new record of blank/zero values into the sharepoint list. This is all good and works as intended.
What I want to achieve is to have the item that is created selected by default or to even simply clear the current selection in Gallery1.
At the moment, if I have an existing item selected and I 'Add New Item' a new item is added however the selected item remains selected.
I have tried: Gallery1.Default = Last(SPList)
Gallery1.Default = Blank()
Gallery1.Default = ContextVariable (set to blank or Last(SPlist)
Gallery1.Default = Variable (set to blank or Last(SPList)
From what I have already read the work around methods are pretty limited. I can not for the life of me work out how to get this to work. Is it even possible?
Thanks in advance
I have been setting a global variable "currentselected"=Gallery1.Selected.ID
I have found that even after creating a new refresh button with onselect= Reset(Gallery1); Set(currentselected, 0) that the gallery is holding onto the previous variable or previous selected item.
Only when I activate my delete button which deletes the record in SP will the Gallery1 reset button properly work.
Perhaps this is also an issue of clearing a global variable too?
Any help would be greatly appreciated
Thanks for the reply,
The Items property of Gallery1 is set to:
SortByColumns(Filter(SharepointList, 'Parent ID' = UpdateTS_ViewGallery.Selected.ID && 'Approval Status'.Value="Pending Approval"),"ID",Descending)
the Default property of Gallery1 is to:
the OnSelect property of Gallery1 is set to:
LineHoursWorked: ThisItem.'Hours Worked',
LineStart: ThisItem.'Start Time',
LineEnd: ThisItem.'End Time',
LineBreak: ThisItem.'Break Time (Minutes)'
This fills out details in an editable gallery below, which has a submit (tick) button which patches the information back to 'SharepointList' and refreshes Gallery1.
Where the problem lies, is as soon as I patch/submit an update (which also refreshes Gallery1 and sets currentscreen=0), Gallery1 is holding onto the previous selection which results in the editable part of the gallery remaining populated.
I would like it to reset the selection to blank or even select the first item in the gallery again (it should as that's what the default property is). This will make the app as foolproof for my users as possible.
Despite my best efforts to clear all current selections in the Gallery1, for some reason it is holding the value Gallery1.Selected.
Sometimes I can even see the first item for a split second becomes selected (good!!) and then the previous item that was selected becomes the selected item.
Ok so that gets me halfway there.
I can't believe a blank Default property was the solution. It is throwing an error because it want's a value, but half of the functionality I need is there.
My Reset button now works and selects the first item in the gallery:
Onselect = Reset(Gallery1); Set(currentselected, Blank())
My new item button which is exactly the same as the rest button but it patches a record of blank values to 'SharepointList' patches yes, but same problem before with the selection, the previously selected item remains selected. Every time I select this I can see the gallery selecting the first item and then returning the selection to the previous item.
I have two buttons outside of Gallery1 we will call them Button1 and Button2
Button1.Onselect = Reset(Gallery1); Set(CurrentSelected, Blank())
Button2.Onselect = Patch(SharepointList, Defaults(SharepointList),
Title: User().FullName & " " & "-" & " " & "WE" & " " & Text(Gallery1.Selected.'Week Ending'),
WeekEnding: Gallery1.'Week Ending'
Button1 works as expected. Resets Gallery1 selection to the first item.
Button2 half works. It creates a new item in SharepointList (the datasource for Gallery1), however the reset part of the command is not being executed. The previously selected item remains selected.
To add another update onto the thread:
I have found that if I separate the Patch of blank values to SharepointList and the Gallery1 reset i can execute both commands successfully with the use of separate buttons.
As soon as I combine these commands onto the Onselect of one button, the Patch executes however the reset does not
OnSelect = Patch(SharepointList, Defaults(SharepointList),
Title: User().FullName & " " & "-" & " " & "WE" & " " & Text(Gallery1.'Week Ending'),
WeekEnding: Gallery1.'Week Ending'
Reset(Gallery1) -> does not execute
I have then attempted to create a timer delay for the two commands so that the patch occurs and then there is a one second delay before the Gallery1 is reset. Still no luck
If anyone has any ideas for a work around, please let me know.
Join us for the next call on August 17, 2022 at 8am PDT.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.