cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rsinha
Helper III
Helper III

If Conditions are not working as expected

Hi,

 

I am working on a Seat Availability App, where in Submit buttion, I have to put some condtions:

1. If any required field is empty, throw a message: Please fill the required fields

2. If Selected date is a past day, throw a message: Selected date can not be before Today's date

3. If a person have booked his/her seat for particular day and location already, then: Oops! looks like you have already booked for this date and location

4. If user chooses Canada and 25 people have already booked for a particular day, then: Oops! No availability for this date, kindly book for some other date or Location

5. If user chooses USA and 100 people have already booked for a particular day, then: Oops! No availability for this date, kindly book for some other date or Location

 

If everything goes well, then Submit the form and popup should appear: Saved successfully.

 

** Here first 3 conditions are working fine, however 4,5 are acting little weird, sometime it throws the "No availability" message even if seats are available for a particular location.

--------------------------------

If(
IsBlank(Location.SelectedItems.Value) || IsBlank(Employee.SelectedItems.DisplayName) || IsEmpty(Employee.SelectedItems.DisplayName) || IsEmpty(Location.SelectedItems.Value),
Notify("Please fill the required fields"),
Date.SelectedDate<Today(),
Notify("Selected date can not be before Today's date"),

If(
CountRows(Filter('Seat Availability',
'Employee Name'.DisplayName= Employee.Selected.DisplayName && Date = Date.SelectedDate && 'Location Name'.Value = Location.Selected.Value))=1,
Notify("Oops! looks like you have already booked for this date and location.."),


CountIf('Seat Availability',
Location.Selected.Value = "Canada" && Date = Date.SelectedDate)<=24
,SubmitForm(Form1); NewForm(Form1); UpdateContext({Popup: true}),Notify("Oops! No availability for this date, kindly book for some other date or Location")

, CountIf('Seat Availability',
Loaction.Selected.Value = "USA" && Date = Date.SelectedDate)<=99
, SubmitForm(Form1); NewForm(Form1); UpdateContext({Popup: true}),Notify("Oops! No availability for this date, kindly book for some other date or Location")


))

----------------------------------------

 

Please help me to rectify the code, its getting very very urgent.

1 ACCEPTED SOLUTION

Accepted Solutions
v-jefferni
Community Support
Community Support

Hi @rsinha ,

 

Please try below instead:

If(
    IsBlank(Location.SelectedItems.Value) || IsBlank(Employee.SelectedItems.DisplayName) || IsEmpty(Employee.SelectedItems.DisplayName) || IsEmpty(Location.SelectedItems.Value),
    Notify("Please fill the required fields"),
    Date.SelectedDate<Today(),
    Notify("Selected date can not be before Today's date"),
    CountRows(Filter('Seat Availability',
    'Employee Name'.DisplayName= Employee.Selected.DisplayName && Date = Date.SelectedDate && 'Location Name'.Value = Location.Selected.Value))=1,
    Notify("Oops! looks like you have already booked for this date and location.."),
    If(
        (Location.Selected.Value = "Canada" && CountIf('Seat Availability','Location Name'.Value = "Canada" && Date = Date.SelectedDate)<=24)) || (Location.Selected.Value = "USA" && CountIf('Seat Availability','Location Name'.Value = "USA" && Date = Date.SelectedDate)<=99),
        SubmitForm(Form1); NewForm(Form1); UpdateContext({Popup: true}),
        Notify("Oops! No availability for this date, kindly book for some other date or Location")
    )
)

 

Best regards,

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

1 REPLY 1
v-jefferni
Community Support
Community Support

Hi @rsinha ,

 

Please try below instead:

If(
    IsBlank(Location.SelectedItems.Value) || IsBlank(Employee.SelectedItems.DisplayName) || IsEmpty(Employee.SelectedItems.DisplayName) || IsEmpty(Location.SelectedItems.Value),
    Notify("Please fill the required fields"),
    Date.SelectedDate<Today(),
    Notify("Selected date can not be before Today's date"),
    CountRows(Filter('Seat Availability',
    'Employee Name'.DisplayName= Employee.Selected.DisplayName && Date = Date.SelectedDate && 'Location Name'.Value = Location.Selected.Value))=1,
    Notify("Oops! looks like you have already booked for this date and location.."),
    If(
        (Location.Selected.Value = "Canada" && CountIf('Seat Availability','Location Name'.Value = "Canada" && Date = Date.SelectedDate)<=24)) || (Location.Selected.Value = "USA" && CountIf('Seat Availability','Location Name'.Value = "USA" && Date = Date.SelectedDate)<=99),
        SubmitForm(Form1); NewForm(Form1); UpdateContext({Popup: true}),
        Notify("Oops! No availability for this date, kindly book for some other date or Location")
    )
)

 

Best regards,

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

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