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.

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.

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
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (4,108)