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

20 REPLIES 20
pword
Helper IV
Helper IV

Hi @StalinPonnusamy , Thank you . But what if it depends on number of days of your leave.  If i want to have a vacation leave of 3 to 5 days up the condition should be enable the 3 days notice before the start day of leave. but if your vacation leave is just 2 days the condition must be false.

StalinPonnusamy
Super User
Super User

Hi @pword

 

  • Are you looking for the submit button to enable based on each leave type?
  • We have been discussing Emergency and now discussing Vacation leave type
  • Let me know the condition for each leave type so that we can work together and provide an answer instead of one by one


Thanks,
Stalin - Learn To Illuminate

Hi @StalinPonnusamy , the emergency leave is still exempted on this condition, my manager final instructions in any leave type  the condition is base on number of days of your leave , if you leave 3 days Up you should file a leave 5 days before your start date leave,  so the submit button should not visible or disable if you file a leave today or 4 days before your leave and your number of days is 3 days up. but when your number of days is 1 or 2 the submit button is visible.

StalinPonnusamy
Super User
Super User

Hi @pword 

 

Set the Display mode of the submit button to

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

 


Thanks,
Stalin - Learn To Illuminate

StalinPonnusamy
Super User
Super User

Hi @pword 

 

If you are looking for a button visible then set the visible property to

With(
    {
        DaysToStart: DateDiff(
            Today(),
            StartDates.SelectedDate,
            Days
        ),
        TotalDays: DateDiff(
            StartDates.SelectedDate,
            EndDates.SelectedDate,
            Days
        )
    },
    If(
        LeaveType.Selected.Value = "Emergency Leave" || TotalDays < 3 || DaysToStart >= 5,
        true,
        false
    )
)

Thank you @StalinPonnusamy  Can i disbale the button if user selected current date?  except emergency leave again

StalinPonnusamy
Super User
Super User

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
    )
)

 

pword
Helper IV
Helper IV

@StalinPonnusamy  I have problem with my holidays, When i filing a leave for Jan 1, 2022 the holiday was included??

Example:

Capture.PNG1.PNG

The number of days should be 2 days

 29, 30(holiday), 31, 1(holiday)

 

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
                )
            )
        ))
    )
)
StalinPonnusamy
Super User
Super User

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.

 

pword
Helper IV
Helper IV

@StalinPonnusamy  I have little problem with my holiday,  Nov. 30 is holiday in my country.  When I file a leave from Nov. 29 to Nov. 30 my number of days is 1  which is correct . but when I file a leave from n Nov 30 to Nov. 30 my number of days is 1 which is wrong. my number of days should be 0 because nov. 30 uis holiday.

 

Holiday.PNG

 

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
                )
            )
        ))
    )
)

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

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.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

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