cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
tianaranjo
Level 8

If, Patch and UpdateContext

I have the following to update a SharePoint list (and collection) If the item doesn't already exist.  For the variable, varAlreadyReg, a popup will appear if the user has already signed up for the selected session.  I would like to also display the popup if the selected item is added to their schedule.  

I have tried inserting Set(varItemAdded, true) within the below If statement without success.  If I insert after the patch, it breaks the Lookup and allows duplicate sessions to be added.  I have tried placing it after the LookUp without success.  Any help would be appreciate.

If( 
IsBlank(LookUp(colMySessions, SessionId = ThisItem.SessionCode)),

Patch(
SessionConfirmation, 
{ 
UserBid: gloThisUserId,
SessionTitle: galAgenda.Selected.Title,
SessionId: galAgenda.Selected.SessionCode,
SessionDay: galAgenda.Selected.DayOfEvent,
SessionStartTime: galAgenda.Selected.StartTime,
SessionEndTime: galAgenda.Selected.EndTime,
SessionLocation: galAgenda.Selected.Location
}

),

Set(varAlreadyReg, true))

 

1 ACCEPTED SOLUTION

Accepted Solutions
jhall
Level 8

Re: If, Patch and UpdateContext

What you're dealing with is that PowerApps If/Then/Else statements are one value only (meaning you can only do one thing per IF or ELSE).  You can of course set your boolean before you do the work and then you can do this fairly easily:

 

Set(varAlreadyReg:!IsBlank(LookUp(colMySessions, SessionId = ThisItem.SessionCode)));
If( !varAlreadyReg, Patch(SessionConfirmation, {UserBid: gloThisUserId,SessionTitle: galAgenda.Selected.Title,SessionId: galAgenda.Selected.SessionCode,SessionDay: galAgenda.Selected.DayOfEvent,SessionStartTime: galAgenda.Selected.StartTime,SessionEndTime: galAgenda.Selected.EndTime,SessionLocation: galAgenda.Selected.Location}))

At this point, the variable varAlreadyReg could be used to display whichever popup you wanted.  I usually do popup's w/ booleans assigned to the Visible property of my dialog boxes anyway so you could at that point follow this w/ similar code to the following:

UpdateContext({showAlreadyReg:varAlreadyReg});
UpdateContext({showNowRegd:!varAlreadyReg});

Then your appropriate popup appears.  Set these two booleans to False for the screen's OnVisible event and set them to False when the user closes the Popup Windows and everything works slick as snot on a doorknob (as my football coach used to say).

1 REPLY 1
jhall
Level 8

Re: If, Patch and UpdateContext

What you're dealing with is that PowerApps If/Then/Else statements are one value only (meaning you can only do one thing per IF or ELSE).  You can of course set your boolean before you do the work and then you can do this fairly easily:

 

Set(varAlreadyReg:!IsBlank(LookUp(colMySessions, SessionId = ThisItem.SessionCode)));
If( !varAlreadyReg, Patch(SessionConfirmation, {UserBid: gloThisUserId,SessionTitle: galAgenda.Selected.Title,SessionId: galAgenda.Selected.SessionCode,SessionDay: galAgenda.Selected.DayOfEvent,SessionStartTime: galAgenda.Selected.StartTime,SessionEndTime: galAgenda.Selected.EndTime,SessionLocation: galAgenda.Selected.Location}))

At this point, the variable varAlreadyReg could be used to display whichever popup you wanted.  I usually do popup's w/ booleans assigned to the Visible property of my dialog boxes anyway so you could at that point follow this w/ similar code to the following:

UpdateContext({showAlreadyReg:varAlreadyReg});
UpdateContext({showNowRegd:!varAlreadyReg});

Then your appropriate popup appears.  Set these two booleans to False for the screen's OnVisible event and set them to False when the user closes the Popup Windows and everything works slick as snot on a doorknob (as my football coach used to say).

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

Follow PowerApps on Twitter

Stay Up-to-Date by following PowerApps on Twitter

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

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

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

Users Online
Currently online: 47 members 4,071 guests
Please welcome our newest community members: