cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Leave Template - Include half day option

I have modified the Leave Template for a team within my company and this is working successfully. However, they require the ability to be able to book a half day's leave. I have looked at several posts within here asking the same question and have tried some of the recommended solutions but absolutely none of them work! This is the most recent one I tried but see that the person that raised it never got any further response when it didn't work for them either:

 

https://powerusers.microsoft.com/t5/Building-Power-Apps/My-leave-request-template-Balance-Add-Select...

 

I understand that the calculation will need to be added under the start date picker but just cannot get anything to work.

 

I would really appreciate some guidance as I've spent hours on trying to find a solution.

 

Thank you in anticipation.

20 REPLIES 20

Yes

 5.JPG

4.JPG

 

but i have problem same you

 

6.JPG

Dovetail
Helper II
Helper II

Hi there @ofmano89 

Did you get it right? I am also facing the same issue.

Total time requested values are staying the same.

If you had a breakthrough, may you kindly assist?

 

Thanks

Anonymous
Not applicable

Thank you to everyone who took the time to respond to my post. I had to give up in the end as I could not get the half day option to work and have spent so much time trying to find a solution.

In the end I created a very simple app based on 2 Sharepoint lists and which is connected to a workflow which deals with approval and also cancellation of leave to update entitlement balances.

 

The annual leave template was nice on the face of it but sometimes less is more and what I have done is working so far for the team that required it.

On top of code suggested by @v-bofeng-msft , you will have to make a few more modifications. I managed to get it working fully. Below are the changes needed:

1. Add 2 more columns to the list: StartDateMeridian, & EndDateMeridian. Both of type string

 

2. HomeScreen: GalleryRequests ->OnSelect

Set(_selectedLeaveItem, ThisItem);

If(_managerView,
//If manager view, get user's leave balance record and determine any overlaps this request has from other people I manage
Set(_requesterBalanceRecord, LookUp(Balance, Year = Text(Year(Now())) && EmployeeEmail = ThisItem.Requester));
ClearCollect(RequestOverlaps, Filter(Leave, EndDate >= _selectedLeaveItem.StartDate && StartDate <= _selectedLeaveItem.EndDate
&& Requester <>_selectedLeaveItem.Requester));

If(CountRows(RequestOverlaps) > 0, Set(_requestOverlapMessage, Concat(Distinct(RequestOverlaps, Requester), Result, ", ")))
);

Concurrent(
//gather requester or approver info depending on view
If(_managerView,
Set(_requester, Office365Users.UserProfile(ThisItem.Requester)),
Set(_selectedApprover, Office365Users.UserProfile(ThisItem.Approver)); If(Office365Users.UserPhotoMetadata(_selectedApprover.Id).HasPhoto, Set(_selectedApproverPhoto, Office365Users.UserPhoto(_selectedApprover.Id)))),
//**** CALCULATION USED TO DETERMINE TOTAL WORK DAYS REQUESTED ****
Set(_inclusiveTotalDaysRequested, DateDiff(ThisItem.StartDate, ThisItem.EndDate, Days) + 1);
Set(_numFullWeeks, RoundDown(_inclusiveTotalDaysRequested / 7, 0));
Set(_numFullDaysPartialWeek, _inclusiveTotalDaysRequested - _numFullWeeks * 7);
Set(_startWeekday, Weekday(ThisItem.StartDate));
Set(_endWeekday, Weekday(ThisItem.EndDate));


//calculates the number of business days in the partial week left over after whole weeks are subtracted out of total days requested
If(_numFullDaysPartialWeek = 6,
If(_startWeekday <= 2, Set(_numPartialWeekdays, 5), Set(_numPartialWeekdays, 4)
),
_numFullDaysPartialWeek = 5,
If(_startWeekday = 2, Set(_numPartialWeekdays, 5), _startWeekday = 1 || _startWeekday = 3 || _startWeekday = 4, Set(_numPartialWeekdays, 4), Set(_numPartialWeekdays, 3)
),
_numFullDaysPartialWeek = 4,
If(_startWeekday = 2 || _startWeekday = 3, Set(_numPartialWeekdays, 4), _startWeekday = 1 || _startWeekday = 4, Set(_numPartialWeekdays, 3), Set(_numPartialWeekdays, 2)
),
_numFullDaysPartialWeek = 3,
If(_startWeekday = 6 || _startWeekday = 7, Set(_numPartialWeekdays, 1), _startWeekday = 1 || _startWeekday = 5, Set(_numPartialWeekdays, 2), Set(_numPartialWeekdays, 3)
),
_numFullDaysPartialWeek = 2,
If(_startWeekday = 7, Set(_numPartialWeekdays, 0), _startWeekday = 1 || _startWeekday = 6, Set(_numPartialWeekdays, 1), Set(_numPartialWeekdays, 2)),
_numFullDaysPartialWeek = 1,
If(_startWeekday = 1 || _startWeekday = 7, Set(_numPartialWeekdays, 0), Set(_numPartialWeekdays, 1)
),
_numFullDaysPartialWeek = 0, Set(_numPartialWeekdays, 0)
);
Set(_workDaysInRequest, _numFullWeeks * 5 + _numPartialWeekdays),
Set(_holidaysInRequest, CountIf(Holidays, StartDate >= ThisItem.StartDate, StartDate <= ThisItem.EndDate)),
Set(_isHalfDay,If(ThisItem.StartDateMeridian = ThisItem.EndDateMeridian, true, false))
);
Set(_requestedDays,If(_isHalfDay, _workDaysInRequest - _holidaysInRequest-0.5,_workDaysInRequest - _holidaysInRequest));
//**** END CALCULATION ****
Set(_showDetails, true);

 

3. NewRequestScreen->OnVisible

Reset(Radio1ForLeaveStartDatePicker);
Reset(Radio2ForLeaveEndDatePicker);
Concurrent(
Select(LeaveStartDatePicker),
Set(_navMenuSelect, ""),
If(!_editingRequest && !_changingApprover,
Set(_leaveStart, Today());
Set(_leaveEnd, Today());
Set(_leaveTitle, "");
Set(_leaveDetail, "");
Reset(LeaveEndDatePicker);
Reset(LeaveStartDatePicker);
Reset(TextInput1);
Reset(TextInput1_1);
Set(_selectedApprover, Office365Users.Manager(_myProfile.Id));
Set(_leaveStartMeridian,"AM");
Set(_leaveEndMeridian,"AM");
Set(_selectedApproverPhoto,
If(Office365Users.UserPhotoMetadata(_selectedApprover.Id).HasPhoto, Office365Users.UserPhoto(_selectedApprover.Id))
)
,
_editingRequest && !_changingApprover,
Set(_selectedApprover, Office365Users.UserProfile(GalleryRequests.Selected.Approver));
Set(_selectedApproverPhoto, Office365Users.UserPhoto(GalleryRequests.Selected.Approver));
Set(_leaveStart, GalleryRequests.Selected.StartDate);
Set(_leaveEnd, GalleryRequests.Selected.EndDate);
If(_leaveEnd < Today(), Notify("This event occurred in the past and cannot be resubmitted without first changing the dates", NotificationType.Warning));
Set(_selectedLeaveType, GalleryRequests.Selected.LeaveType);
Set(_leaveTitle, GalleryRequests.Selected.Title);
Set(_leaveDetail, GalleryRequests.Selected.Detail);
Set(_leaveStartMeridian, GalleryRequests.Selected.StartDateMeridian);
Set(_leaveEndMeridian, GalleryRequests.Selected.EndDateMeridian);
)
);
Set(_changingApprover, false)

 

4. ConfirmationScreen-> OnVisible

 

If(
_submittingRequest,
Concurrent(
Set(
_navMenuSelect,
""
),
//if editing a request, revise the record that is being edited, otherwise create a new one
Patch(
Leave,
If(
_editingRequest,
LookUp(
Leave,
LeaveID = GalleryRequests.Selected.LeaveID
),
Defaults(Leave)
),
{
Title: TextInput1.Text,
Detail: TextInput1_1.Text,
StartDate: LeaveStartDatePicker.SelectedDate,
EndDate: LeaveEndDatePicker.SelectedDate,
LeaveType: _selectedLeaveType,
Approver: _selectedApprover.UserPrincipalName,
Status: "Pending",
Requester: _myProfile.UserPrincipalName,
StartDateMeridian:Radio1ForLeaveStartDatePicker.Selected.Value,
EndDateMeridian:Radio2ForLeaveEndDatePicker.Selected.Value,
LeaveID: If(
_editingRequest,
GalleryRequests.Selected.LeaveID,
Text(
Now(),
DateTimeFormat.LongDateTime24
) & _myProfile.UserPrincipalName
)
}
),
//create email template data specific to the request
ClearCollect(
TemplateData,
{
Field: "{SubmitterName}",
Data: _myProfile.DisplayName
},
{
Field: "{LeaveType}",
Data: _selectedLeaveType
},
{
Field: "{LeaveTitle}",
Data: TextInput1.Text
},
{
Field: "{LeaveDescript}",
Data: TextInput1_1.Text
},
{
Field: "{LeaveStart}",
Data: Text(
LeaveStartDatePicker.SelectedDate,
"[$-en-US]mmm. dd, yyyy"
)
},
{
Field: "{LeaveEnd}",
Data: Text(
LeaveEndDatePicker.SelectedDate,
"[$-en-US]mmm. dd, yyyy"
)
}
)
);
//substitute template data values for placeholder
ForAll(
TemplateData,
Patch(
EmailTemplate,
First(EmailTemplate),
{
Value: Substitute(
First(EmailTemplate).Value,
Field,
Data
)
}
)
);
//send email with email template
Office365Outlook.SendEmailV2(
_selectedApprover.UserPrincipalName,
"New Leave Request",
First(EmailTemplate).Value,
{Importance: "Normal"}
);

//reset all user nput fields
Set(
_submittingRequest,
false
);
Set(
_leaveStart,
Today()
);
Set(
_leaveEnd,
Today()
);
Set(
_leaveTitle,
""
);
Set(
_leaveDetail,
""
);
Set(
_selectedLeaveType,
Blank()
);
Reset(TextInput1);
Reset(TextInput1_1);
//reset email template to placeholder values when finished (see phone version for an alternate method of doing this)
ClearCollect(
EmailTemplate,
"<html>
<head>
<meta http-equiv=""Content-Type"" content=""text/html; charset=us-ascii"">
</head>
<body>
<p>
There is a leave request from: {SubmitterName} pending your approval. <ul><li>Type: {LeaveType}</li><li>Title: {LeaveTitle}</li><li>Description: {LeaveDescript}</li><li>Start Date: {LeaveStart}</li><li>End Date: {LeaveEnd}</li>" & "</p>
</body>
</html>"
);

)

 

 

zmm14
Helper III
Helper III

Hi I did all this and cant get it to work

zmm14_0-1624955238069.png

 

zmm14_1-1624955316706.png

 

After adding the 2 columns to datasource, refresh it and the error will go.

Dovetail
Helper II
Helper II

Hello there,

The patch function on number 4 of the provided code is throwing an error:

"This type of argument 'LeaveType' does not match the expected type 'Text'. Found type error"

Dovetail_1-1626379998805.png

May you please assist on how to get rid of this error.

 

Thank you

HI Moreshwar, On what sheet of the datasourse do I add the twocolumns?

Hello SHewson - Add the columns in Leave worksheet.

Hello Dovetail - Check your _leaveTypeVariable, it should be of type text. For testing you may want to hardcode values and tryout.

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!      

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Community Roundup: A Look Back at Our Last 10 Tuesday Tips

As we continue to grow and learn together, it's important to reflect on the valuable insights we've shared. For today's #TuesdayTip, we're excited to take a moment to look back at the last 10 tips we've shared in case you missed any or want to revisit them. Thanks for your incredible support for this series--we're so glad it was able to help so many of you navigate your community experience!   Getting Started in the Community An overview of everything you need to know about navigating the community on one page!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Ranks and YOU Have you ever wondered how your fellow community members ascend the ranks within our community? We explain everything about ranks and how to achieve points so you can climb up in the rankings! Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Powering Up Your Community Profile Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile. Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Blogs--A Great Place to Start There's so much you'll discover in the Community Blogs, and we hope you'll check them out today!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Unlocking Community Achievements and Earning Badges Across the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. Check out some details on Community badges--and find out more in the detailed link at the end of the article! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Blogging in the Community Interested in blogging? Everything you need to know on writing blogs in our four communities! Get started blogging across the Power Platform communities today! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Subscriptions & Notifications We don't want you to miss a thing in the community! Read all about how to subscribe to sections of our forums and how to setup your notifications! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Getting Started with Private Messages & Macros Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Community User Groups Learn everything about being part of, starting, or leading a User Group in the Power Platform Community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Update Your Community Profile Today! Keep your community profile up to date which is essential for staying connected and engaged with the community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Thank you for being an integral part of our journey.   Here's to many more Tuesday Tips as we pave the way for a brighter, more connected future! As always, watch the News & Announcements for the next set of tips, coming soon!

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

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