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 III
Super User III

@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 III
Super User III

@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
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 Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors
Users online (2,055)