cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pword
Helper IV
Helper IV

Onchange Properties

 Hi All,  Onchange properties on my dropdown if  you selected "N/A"  UpdateContext({varCalculationActive1: false}) and when you select "Paid"  UpdateContext({varCalculationActive1: true}), now i want automatic change my dropdown to N/A and my number of days should be zero and disabled all the Paid leave fields, if the Value of Remaining leave is zero. 

 

Update : I can now manage to automatic change my dropdown to "N/A"  once the remaining leave is zero using the code in my defaultselected item properties and disabled it. but my problem now is my number of days is not changing.

 

Onchange properties dropdown:

 

 

If(
    PaidDrop.Selected.Value = "Paid",
    UpdateContext({varCalculationActive1: true}) || PaidDrop.Selected.Value = "N/A",
    UpdateContext({varCalculationActive1: false})
    )

 

 

 

DefaultSelectedItem:

 

 

If(
    Leavetype.Selected.Value = "Paternity leave" && Value(TextInput1_12.Text) = 0 || Leavetype.Selected.Value = "Vacation Leave" && Value(TextInput1_9.Text) = 0 || Leavetype.Selected.Value = "Sick Leave" && Value(TextInput1_9.Text) = 0 || Leavetype.Selected.Value = "Emergency Leave" && Value(TextInput1_9.Text) = 0 || Leavetype.Selected.Value = "Maternity leave" && Value(TextInput1_21.Text) = 0 || Leavetype.Selected.Value = "Bereavement Leave" && Value(TextInput1_24.Text) = 0 || Leavetype.Selected.Value = "Leave for Victim of Violence (Women&Children)" && Value(TextInput1_27.Text) = 0 || Leavetype.Selected.Value = "Parental Leave for Solo Parent" && Value(TextInput1_18.Text) = 0 || Leavetype.Selected.Value = "Special Leave for Women" && Value(TextInput1_30.Text),
    Table({Value: "N/A"}),
    Table({Value: "Paid"})
)

 

 

number of days

If(varCalculationActive1,
 If(

        Leavetype.Selected.Value = "Maternity leave",
        If(
            StartDates.SelectedDate <= EndDates.SelectedDate,
            DateDiff(
                StartDates.SelectedDate,
                EndDates.SelectedDate,
                Days
            ) + 1 - If(
                Checkbox3.Value,
                0.5
            )
        ),
        (If(
            StartDates.SelectedDate = EndDates.SelectedDate,
            Sum(
                If(
                    Weekday(StartDates.SelectedDate) = 1,
                    0,
                    1
                )
            ) - If(
                Checkbox3.Value,
                0.5
            ),
            If(
                StartDates.SelectedDate > EndDates.SelectedDate,
                -Sum(
                    ForAll(
                        Sequence(
                            DateDiff(
                                EndDates.SelectedDate,
                                StartDates.SelectedDate,
                                Days
                            ),
                            0,
                            1
                        ),
                        If(
                            Weekday(
                                DateAdd(
                                    EndDates.SelectedDate,
                                    Value
                                )
                            ) = 1,
                            {DayCount: 0},
                            {DayCount: 1}
                        )
                    ),
                    DayCount
                ) - If(
                    Checkbox3.Value = false,
                    0.5
                ) - 1/2,
                Sum(
                    ForAll(
                        Sequence(
                            DateDiff(
                                StartDates.SelectedDate,
                                EndDates.SelectedDate,
                                Days
                            ),
                            0,
                            1
                        ),
                        If(
                            Weekday(
                                DateAdd(
                                    StartDates.SelectedDate,
                                    Value
                                )
                            ) = 1,
                            {DayCount: 0},
                            {DayCount: 1}
                        )
                    ),
                    DayCount
                ) + If(
                    Checkbox3.Value = false,
                    0.5
                ) + 1 / 2
            ) - CountRows(
                Filter(
                    colHolidays,
                    HolidayDates >= StartDates.SelectedDate,
                    HolidayDates <= EndDates.SelectedDate
                )
            )
        ))
    )
 )

 

zero.PNG

 

Can you help me with this? Thank you

2 ACCEPTED SOLUTIONS

Accepted Solutions
StalinPonnusamy
Community Champion
Community Champion

Hi @pword 

 

  • Aways enable for Sick Leave and Emergency Leave
  • Disable for Current Date
  • Disable if Total days > 3 && Start date from current date < 5

 

With(
    {
        DaysToStart: DateDiff(
            Today(),
            StartDates.SelectedDate,
            Days
        ),
        TotalDays: DateDiff(
            StartDates.SelectedDate,
            EndDates.SelectedDate,
            Days
        )
    },
    If(
        LeaveType.Selected.Value = "Emergency Leave" || LeaveType.Selected.Value = "Sick Leave" || (DaysToStart > 0 && (TotalDays < 3 || DaysToStart >= 5)),
        DisplayMode.Edit,
        DisplayMode.Disabled
    )
)

 

View solution in original post

StalinPonnusamy
Community Champion
Community Champion

Hi @pword 

 

I just tested with Holidays and works fine. Please make sure you have holidays added to the SP list and Added to Collection as well. Like below

 

ClearCollect(
    colHolidays,
    {HolidayDates: DateValue("01/01/2021")},
    {HolidayDates: DateValue("05/02/2021")},
    {HolidayDates: DateValue("12/25/2021")},
    {HolidayDates: DateValue("1/1/2022")}
)

 

I Added the holidays to the collection and tested it. It works fine.

 

View solution in original post

19 REPLIES 19
StalinPonnusamy
Community Champion
Community Champion

Hi @pword 

 

We are doing leave calculation when varCalculationActive1 is true but on false old values retains. We need to add ",0" at the second end of the line. So please update to

If(varCalculationActive1,
 If(

        Leavetype.Selected.Value = "Maternity leave",
        If(
            StartDates.SelectedDate <= EndDates.SelectedDate,
            DateDiff(
                StartDates.SelectedDate,
                EndDates.SelectedDate,
                Days
            ) + 1 - If(
                Checkbox3.Value,
                0.5
            )
        ),
        (If(
            StartDates.SelectedDate = EndDates.SelectedDate,
            Sum(
                If(
                    Weekday(StartDates.SelectedDate) = 1,
                    0,
                    1
                )
            ) - If(
                Checkbox3.Value,
                0.5
            ),
            If(
                StartDates.SelectedDate > EndDates.SelectedDate,
                -Sum(
                    ForAll(
                        Sequence(
                            DateDiff(
                                EndDates.SelectedDate,
                                StartDates.SelectedDate,
                                Days
                            ),
                            0,
                            1
                        ),
                        If(
                            Weekday(
                                DateAdd(
                                    EndDates.SelectedDate,
                                    Value
                                )
                            ) = 1,
                            {DayCount: 0},
                            {DayCount: 1}
                        )
                    ),
                    DayCount
                ) - If(
                    Checkbox3.Value = false,
                    0.5
                ) - 1/2,
                Sum(
                    ForAll(
                        Sequence(
                            DateDiff(
                                StartDates.SelectedDate,
                                EndDates.SelectedDate,
                                Days
                            ),
                            0,
                            1
                        ),
                        If(
                            Weekday(
                                DateAdd(
                                    StartDates.SelectedDate,
                                    Value
                                )
                            ) = 1,
                            {DayCount: 0},
                            {DayCount: 1}
                        )
                    ),
                    DayCount
                ) + If(
                    Checkbox3.Value = false,
                    0.5
                ) + 1 / 2
            ) - CountRows(
                Filter(
                    colHolidays,
                    HolidayDates >= StartDates.SelectedDate,
                    HolidayDates <= EndDates.SelectedDate
                )
            )
        ))
    ),0
)
StalinPonnusamy
Community Champion
Community Champion

Hi @pword 

 

Are you still having issues? Please let us know if anything needs on your post. We can help with this.

Please mark the post as Solved If I have answered your question.
Please give it a Thumbs Up if you find the suggestion helpful

Thanks,
Stalin - Learn To Illuminate

Thank you @StalinPonnusamy  its working now

hi @StalinPonnusamy, My manager wants to have a condition on my Leave System App, the user should file a leave 3 days before the startdate else the submit button was disbable if the user file a leave today or  2 days before the start date., but in emergency leave type you can file a leave any day.  Can you help me with this?

StalinPonnusamy
Community Champion
Community Champion

Hi @pword 

 

Set the visible property of the submit button to

 

DateDiff(Today(),StartDates.SelectedDate, Days) >= 3

 

 

You may be setting the display mode of the submit button to edit  or disable instead of visible like below (In this case visible always true)

 

If(DateDiff(Today(),StartDates.SelectedDate, Days) >= 3,DisplayMode.Edit,DisplayMode.Disabled)

 

 

StalinPonnusamy_0-1635605375757.png

 


Thanks,
Stalin - Learn To Illuminate

 

Hi @StalinPonnusamy , it's working. Thank you, but how can i exclude the leave type emergnecy leave in that condition??

StalinPonnusamy
Community Champion
Community Champion

Hi @pword 

 

If(LeaveType.Selected.Value = "Emergency Leave" || DateDiff(Today(),StartDates.SelectedDate, Days) >= 3,DisplayMode.Edit,DisplayMode.Disabled)

 


Thanks,
Stalin - Learn To Illuminate

Hi @StalinPonnusamy, Thank you , but my submit button still not visible when i choose emergency leave and file a leave today. You can file a Emergency leave any day

StalinPonnusamy
Community Champion
Community Champion

Hi @pword 

 

To Set Visible property

LeaveType.Selected.Value = "Emergency Leave" || DateDiff(Today(),StartDates.SelectedDate, Days) >= 3

 

StalinPonnusamy_0-1635819828969.png

 

To set Display mode

StalinPonnusamy_1-1635819938850.png

 

StalinPonnusamy_2-1635819998305.png

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,673)