cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

Patch SP List + - Count and then evaluate Seat Total to Seats Remaining

Hi,

 

I have two SP Lists as follows:

 

  • SP List B - records people interactions with a 'SignUp' toggle (adds record). Column 'Session Title' is patched to the ThisItem.Title (as shown in the code below for the 'SignUp' toggle). When the toggle is clicked the TrueText property changes the toggle text to "Remove SignUp" (removes record). 
  • SP List A - contains session data for a movie or convention. Important in this context of the help I need is the single text columns of Seat Total and Seats Remaining. 

 

What do I want to accomplish? 

Whenever the SignUp toggle is pressed, I want to evaluate and patch (SUBTRACT) the Seats Remaining column in SP List A by the difference of Seat Total column. However, please read....The evaluation needs to take into account the total count of existing {'Session Title': Title} from SP List B and then subtract that count total from Seat Total in SP List A, which gives the Seats Remaining value.

 

If the person returns to this page and the toggle text now say's "Remove SignUp', then we do the inverse of above and ADD the seat back to the Seats Remaining column by the evaluation of counting of Titles.

 

Can someone help with the code and placement inside below to allow this to work? I have experience with very simple +/- of a single item but not with how the evaluation needs to count first and then perform the calculation.

 

OnChange Toggle is as follows for: 'SignUp' and 'Remove SignUp'

If(
    Toggle1.Value,
    Patch(                       // Add new record 
           'SP List B', 
            Defaults('Event Registration'), 
            {
              Title: "REGISTERED",
              FirstName: Office365Users.MyProfile().GivenName,
              LastName: Office365Users.MyProfile().Surname,
              Email: Office365Users.MyProfile().Mail,
              'Session Title': Title,
              Registered: "Yes"
                           
            }
    ),
    RemoveIf(
        'SP List B',
        'Session Title'=ThisItem.Title
    )
)

 

Thanks,

 

Tom

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Hi @Gigaenvy

 

I am confused with the statement "Column 'Session Title is patched to the ThisItem.Title". Where is the toggle? Does it stand in a Gallery? What is the data source of gallery? Could you share more details and screenshots with that? 

What's more, what does "take into account the total count of existing {'Session Title': Title} " mean?  

From my experience, each time the toggle is turned on, also subtract 1 from the Seats remaining. When the toggle is turned off, just add 1 from the Seats remaining.

 

 

If(
    Toggle1.Value,
    Patch(                       // Add new record 
           'SP List B', 
            Defaults('Event Registration'), 
            {
              Title: "REGISTERED",
              FirstName: Office365Users.MyProfile().GivenName,
              LastName: Office365Users.MyProfile().Surname,
              Email: Office365Users.MyProfile().Mail,
              'Session Title': Title,
              Registered: "Yes"
                           
            };
    Patch('SP list A', ThisItem,{'Seats Remaining': ThisItem.'Seats Remaining' +1})
    ),
    RemoveIf(
        'SP List B',
        'Session Title'=ThisItem.Title
    );
    Patch('SP list A', ThisItem,{'Seats Remaining': ThisItem.'Seats Remaining' -1})
)

 

Sik

View solution in original post

2 REPLIES 2
Highlighted
Community Support
Community Support

Hi @Gigaenvy

 

I am confused with the statement "Column 'Session Title is patched to the ThisItem.Title". Where is the toggle? Does it stand in a Gallery? What is the data source of gallery? Could you share more details and screenshots with that? 

What's more, what does "take into account the total count of existing {'Session Title': Title} " mean?  

From my experience, each time the toggle is turned on, also subtract 1 from the Seats remaining. When the toggle is turned off, just add 1 from the Seats remaining.

 

 

If(
    Toggle1.Value,
    Patch(                       // Add new record 
           'SP List B', 
            Defaults('Event Registration'), 
            {
              Title: "REGISTERED",
              FirstName: Office365Users.MyProfile().GivenName,
              LastName: Office365Users.MyProfile().Surname,
              Email: Office365Users.MyProfile().Mail,
              'Session Title': Title,
              Registered: "Yes"
                           
            };
    Patch('SP list A', ThisItem,{'Seats Remaining': ThisItem.'Seats Remaining' +1})
    ),
    RemoveIf(
        'SP List B',
        'Session Title'=ThisItem.Title
    );
    Patch('SP list A', ThisItem,{'Seats Remaining': ThisItem.'Seats Remaining' -1})
)

 

Sik

View solution in original post

Highlighted

Thanks this worked well and thank you so much for trying to understand what I wrote. You nailed it with the exception of some syntax which was corrected as it wasn't throwing an error on an expression.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (7,813)