cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PPSA
Resolver II
Resolver II

Gallery is losing selected item after an update if

Hi all,

I have a series of buttons within a gallery, this gallery's items is based on the selected item from the gallery before.

I can press the buttons and my functions work as planned with no problems

I have just added an 'update if ' to the end of my code for a certain button, it works as planned but after pressing my gallery items disappear, the labels on screen which show which item is selected prove that it isn't recognizing the previous selected item.

I don't have a refresh built in or anything.

Some images attached , 2nd image is after pressing Stop - the other 3 buttons don't cause this to happen.First screenFirst screen2nd screen2nd screen
All buttons showingAll buttons showing
And finally, code of the troublesome stop button, apologies for the length of it, sure it could be done better, but as I say, was working fine up until the now Italic and underlined section.



Patch(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
),
{Title: Gallery13.Selected.Title},
{
Title: Gallery13.Selected.Title,
Stop: Now(),
Elapsed: DateDiff(
LookUp(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
),
Title = Gallery13.Selected.Title,
Start
),
Now(),
Minutes
),
TotalPauseTime: Sum(
Filter(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
),
Title = ThisItem.Title
),
PauseTime
)
}
);
Patch(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
),
{Title: Gallery13.Selected.Title},
{
Title: Gallery13.Selected.Title,
ActWorkingTime: Sum(
Last(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
)
).Elapsed - Last(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
)
).TotalPauseTime
),
NumberOfBreaks: Sum(
CountIf(
Filter(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
),
Title = ThisItem.Title
),
!IsBlank(Unpause)
)
),
Status: "OpComplete",
Start: LookUp(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
),
Title = Gallery13.Selected.Title,
Start
),
Stop: LookUp(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
),
Gallery13.Selected.Title = Title && !IsBlank(Stop),
Stop
),
Elapsed: DateDiff(
LookUp(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
),
Gallery13.Selected.Title = Title,
Start
),
Now(),
Minutes
),
TotalPauseTime: Sum(
Filter(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
),
Title = ThisItem.Title
),
PauseTime
)
}
);
If(
ThisItem.Operation = "Cutting",
UpdateIf(
'Steel Jobs',
JobNumber = Gallery13.Selected.Title,
{
ActCuttingTime: Sum(
Last(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
)
).Elapsed - Last(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
)
).TotalPauseTime
)
}
),
ThisItem.Operation = "Drilling",
UpdateIf(
'Steel Jobs',
JobNumber = Gallery13.Selected.Title,
{
ActDrillingTime: Sum(
Last(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
)
).Elapsed - Last(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
)
).TotalPauseTime
)
}
),
ThisItem.Operation = "Welding",
UpdateIf(
'Steel Jobs',
JobNumber = Gallery13.Selected.Title,
{
ActWeldingTime: Sum(
Last(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
)
).Elapsed - Last(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
)
).TotalPauseTime
/60)
}
),
ThisItem.Operation = "Inspection",
UpdateIf(
'Steel Jobs',
JobNumber = Gallery13.Selected.Title,
{
ActInspectionTime: Sum(
Last(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
)
).Elapsed - Last(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
)
).TotalPauseTime
)
}
),
ThisItem.Operation = "Assembly",
UpdateIf(
'Steel Jobs',
JobNumber = Gallery13.Selected.Title,
{
ActAssemblyTime: Sum(
Last(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
)
).Elapsed - Last(
If(
ThisItem.Operation = "Cutting",
TempCuttingTimeLog,
ThisItem.Operation = "Drilling",
TempDrillingTimeLog,
ThisItem.Operation = "Welding",
TempWeldingTimeLog,
ThisItem.Operation = "Inspection",
TempInspectionTimeLog,
ThisItem.Operation = "Assembly",
TempAssemblyTimeLog
)
).TotalPauseTime
)
}
)
)

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Super User
Super User

@PPSA 

Best way to solve this is to reference a variable instead.  When the user clicks on the Gallery1 run this code using the OnSelect property.

 

Set(varGalleryRecord, ThisItem)

 

Then change any references to Gallery1.Selected.Value to varGalleryRecord instead.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

3 REPLIES 3
mdevaney
Super User
Super User

@PPSA 

Best way to solve this is to reference a variable instead.  When the user clicks on the Gallery1 run this code using the OnSelect property.

 

Set(varGalleryRecord, ThisItem)

 

Then change any references to Gallery1.Selected.Value to varGalleryRecord instead.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

Thanks, @mdevaney , I've changed all references and it is still happening, sometimes it works fine, others it loses the item.

2020-07-13 15_01_27-Steel - Tablet v4 - Saved (Unpublished) - Power Apps.png


 

I've double checked I haven't missed any references using Word too.

May have to add a navigate back to first screen on the end, not ideal but will cover up the issue.

Without changing anything from my last post, it does now seem to be working, thank you @mdevaney 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,361)