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

Validating using Dropdown list

Hi all,

I am having a dropdown list at the beginning of the form. Based on the value in the dropdown list the below functions work.

Values in dropdown are Normal and Ad-hoc. This is the code in Visible property of Form,

If(
    DataCardValue1.Selected.Value = "Normal",
    If(
        Weekday(
            Today() + 10,
            StartOfWeek.Sunday
        ) = 1,
        Set(
            varDate,
            Today() + 4
        ),
        Weekday(
            Today() + 10,
            StartOfWeek.Sunday
        ) = 5,
        Set(
            varDate,
            Today() + 4
        ),
        Weekday(
            Today() + 4,
            StartOfWeek.Sunday
        ) = 3,
        Set(
            varDate,
            Today() + 4
        ),
        Weekday(
            Today() + 10,
            StartOfWeek.Sunday
        ) = 3,
        Set(
            varDate,
            Today() + 4
        ),
        Weekday(
            Today() + 10,
            StartOfWeek.Sunday
        ) = 4,
        Set(
            varDate,
            Today() + 4
        ),
        Weekday(
            Today() + 10,
            StartOfWeek.Sunday
        ) <> 7 && Weekday(
            Today() + 10,
            StartOfWeek.Sunday
        ) <> 1 && Weekday(
            Today() + 10,
            StartOfWeek.Sunday
        ) <> 3 && Weekday(
            Today() + 10,
            StartOfWeek.Sunday
        ) <> 4,
        Set(
            varDate,
            Today() + 13
        )
    ),
    DataCardValue1.Selected.Value = "Ad-hoc",
    If(
        Weekday(
            Today() + 3,
            StartOfWeek.Sunday
        ) = 1,
        Set(
            varDate1,
            Today() + 4
        ),
        Weekday(
            Today() + 3,
            StartOfWeek.Sunday
        ) = 7,
        Set(
            varDate1,
            Today() + 4
        ),
        Weekday(
            Today() + 4,
            StartOfWeek.Sunday
        ) = 3,
        Set(
            varDate1,
            Today() + 4
        ),
        Weekday(
            Today() + 3,
            StartOfWeek.Sunday
        ) = 3,
        Set(
            varDate1,
            Today() + 4
        ),
        Weekday(
            Today() + 3,
            StartOfWeek.Sunday
        ) = 4,
        Set(
            varDate1,
            Today() + 3
        ),
        Weekday(
            Today() + 3,
            StartOfWeek.Sunday
        ) <> 7 && Weekday(
            Today() + 3,
            StartOfWeek.Sunday
        ) <> 1 && Weekday(
            Today() + 3,
            StartOfWeek.Sunday
        ) <> 3 && Weekday(
            Today() + 3,
            StartOfWeek.Sunday
        ) <> 4,
        Set(
            varDate1,
            Today() + 2
        )
    )
)

 And this the code for errormessage label in Normal,

Parent.DisplayMode = DisplayMode.Edit && If(
    DataCardValue1.Selected.Value = "Normal",
    If(
        DateValue2.SelectedDate < Today() Or Weekday(DateValue2.SelectedDate) = 1 Or Weekday(DateValue2.SelectedDate) = 7 Or DateValue2.SelectedDate > varDate Or DateTimeValue(DateValue2.SelectedDate & " " & HourValue2.Selected.Value & ":" & MinuteValue2.Selected.Value) < Now(),
        true,
        false
    ),
    false
)

And this is the code for errormessage label in Ad-hoc,

Parent.DisplayMode = DisplayMode.Edit && If(
    DataCardValue1.Selected.Value = "Ad-hoc",
    If(
        DateValue2.SelectedDate < Today() Or Weekday(DateValue2.SelectedDate) = 1 Or Weekday(DateValue2.SelectedDate) = 7 Or DateValue2.SelectedDate > varDate1 Or DateTimeValue(DateValue2.SelectedDate & " " & HourValue2.Selected.Value & ":" & MinuteValue2.Selected.Value) < Now(),
        true,
        false
    ),
    false
)

But this is not working as expected. 
Basically, Normal enables to select date within 10 days and Ad-hoc enables to select date within 3 days. Which is working perfectly when tested individually but when combined like above, I am not getting any error message or not validating the code.

 

Please help.

1 ACCEPTED SOLUTION

Accepted Solutions
v-jefferni
Community Support
Community Support

Hi @ramanan89 ,

 

Could you please share more details about your scenario? What do you mean by "working perfectly when tested individually but when combined"? And I don't understand why the If statement is in Visible of the form since the If statement could only return results of two variables and both of them are Date values. Did this not cause errors?

 

If you mean the individual If statements could work, you could have a try to divide the whole statement into two parts and see if it could work.

 

If you have further information, please let me know .

 

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.

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

2 REPLIES 2
v-jefferni
Community Support
Community Support

Hi @ramanan89 ,

 

Could you please share more details about your scenario? What do you mean by "working perfectly when tested individually but when combined"? And I don't understand why the If statement is in Visible of the form since the If statement could only return results of two variables and both of them are Date values. Did this not cause errors?

 

If you mean the individual If statements could work, you could have a try to divide the whole statement into two parts and see if it could work.

 

If you have further information, please let me know .

 

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.

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.

Thanks. I was able to find it myself, I had to refine the code and it worked after some changes. Please close the topic.

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,167)