cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Julien2
Level: Powered On

Leave request flow with sharepoint

Hello everyone !

I have 2 lists in SharePoint:
-Leave Request: Contain 3 columns (Title, StartDate, EndDate).
-Employee Leave Request Dashboard: Contain 4 columns (Title,EmployeeName,Amount of Annual Leave, Balance of Annual).


I want to create one flow for both lists:

1. For Leave request:
When the item is created in SharePoint.
-I want to add conditons to check first if the employee request a vacation more than 3 days to send an approval to Manager and HR.
-If the leave request of the employee is less than 3 days i want to send only the email for the HR without sending to Manager.

 

2. For Employee Leave Request Dashboard: (Note: Total of Annual Leaves is 15 days by default).
-Suppose i am the manager or HR and i want to approve the leave request for this employee that he request a vacation for 3 days.

If someone of them approved the Leave request i want to update the Balance of Annual column to show the total for remaining days for his vacation.


-I should subtract the balance of annual (-) the amount of annual. (So If he requested 3 days and the leave request is approved the column will be (15-3) = 12 days).


-If its rejected the balance will remain the same. (15 days).

 

So any suggestion how to build this flow and what are the expressions i have to use to calculate the dates ?

(I am using the dates based on the calendar)(SAME YEAR).

 

Thank you!!

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Leave request flow with sharepoint

@Julien2 

Please take a look at my solution below and let me know if you have any questions.  Dates need to be converted to ticks in order to get the difference in days.

Any expression that I used can be seen in the comments area.

LeaveDashboard1.jpgLeaveDashboard2.jpgLeaveDashboard3.jpgLeaveDashboard4.jpgLeaveDashboard5.jpgLeaveDashboard6.jpg

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

View solution in original post

17 REPLIES 17
Super User
Super User

Re: Leave request flow with sharepoint

@Julien2 

Please take a look at my solution below and let me know if you have any questions.  Dates need to be converted to ticks in order to get the difference in days.

Any expression that I used can be seen in the comments area.

LeaveDashboard1.jpgLeaveDashboard2.jpgLeaveDashboard3.jpgLeaveDashboard4.jpgLeaveDashboard5.jpgLeaveDashboard6.jpg

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

View solution in original post

Julien2
Level: Powered On

Re: Leave request flow with sharepoint

Hello @ScottShearer 

 

First of all, thanks for your help.


I have an error in last condition "Update dashboard if approved" with Get_items.

 

The Get_items should trigger the same empolyee name in Leave Request List and in Employee Leave Request Dashboard list.


For example: If "Jennifer" created the item in Leave request list, the Get_items should trigger the same employee name in Employee Leave Request Dashboard to update the balance column for the appropriate Employee Name.

 

Leave Request_LI.jpg

LeaveRequestDashboard.PNG


The error details of "Get_Items":

ActionFailed.PNG


I have a question about this expression:

 

div(sub(variables('End Date Ticks'),variables('Start Date Ticks')),864000000000)


What does 864000000000 means ?

 

Thanks again!

Super User
Super User

Re: Leave request flow with sharepoint

@Julien2 

First, 864000000000 is the numbre of ticks in a day.

In my example, employee name is a person or group column - you have it as a text column and that is why you see the error.  Your best bet is to use a person or group column in the dashboard rather than a text column.  Otherwise, it will be difficult to link the request to the dashboard.  Also, please note the single quotes around EmployeeName in my query.

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Julien2
Level: Powered On

Re: Leave request flow with sharepoint

@ScottShearer 

 

Thanks for replying so quickly.

 

I changed the type of both columns in both lists to "Person or Group" and i edit the flow as below:

 

CaptureActionFailed.PNG

But the error remain the same. An action failed. No dependent actions succeeded: Bad Requests:

Status "400" The expression "flowtesting@test.com eq 'flowtesting@test.com'" is not valid.

I also tried this way:

Thisway.PNG

And i get the following error:

"$filter": "EmployeeName eq 'flowtesting@.com' "
"body": {
    "status": 400,
    "message": "Column 'EmployeeName' does not exist. It may have been deleted by another user.\r\nclientRequestId: bb5631ac-786f-4410-8412-98715d403c5b\r\nserviceRequestId: bb5631ac-786f-4410-8412-98715d403c5b"
  }

The EmployeeName already exist in my list i have no idea why i am getting this error.

 

I created first a new item with flowtesting email in the dashboard list  with default annual leave number which is 15.

 

Then i created another new item in the Leave request with the same email flowtesting that he request 5 days. To start the flow.

Super User
Super User

Re: Leave request flow with sharepoint

@Julien2 

Did you change the column in the Dashboard to a person or group column?  For my solution to work, you must make it a person or group column.

The issue with your expression is how you are referencing the employee name column.

Here is an easy way to see how you should reference the column:

  1. Create a new Flow with a button trigger
  2. After the button, use a SharePoint get items trigger and configure it to get items from the Dashboard list
  3. Run the Flow
  4. Take a look at the run and click on Get items
    1. Go to the body section at the bottom
    2. Look for a reference to your Employee name column - you must refer to the column in exactly the same way as it appears here

Please let me know the results.

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Julien2
Level: Powered On

Re: Leave request flow with sharepoint

 

@ScottShearer 

 

Yes i have changed in both lists EmployeeName to type of person or group.

 

After implementing the trigger flow you tell me about now the flow ran successfully after refering to the column in exactly the same way as it appears in the trigger.

 

But we have another problem now in the last step, the Leave days is not subtracting the BalanceofAnnual to show the remaining days for the specific employee in the dashboard.

 

Maybe because the column type of BalanceofAnnual is text ? or something wrong with the expressions ?

 

Here are some screenshots:

Capturea.PNG

Remain15.PNG

In the dashboard the BalanceofAnnual should be 11 but in the above screenshot remain 15.

 

and here the flow results:

AfterRunning.PNG

Thank you!

Super User
Super User

Re: Leave request flow with sharepoint

@Julien2 

You're almost there..

Please post a screen shot of the Flow for the Get items action and everything below it.  Please add any expression that you used to the comments for that action as I did in my example - that will make it easy to see.

Alos, click on the leave days variable in your run - what value does it show?

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Julien2
Level: Powered On

Re: Leave request flow with sharepoint

@ScottShearer 

 

So this is a screenshot about how i implemented and i add the expressions in a comment for each action as you did it.

 

CaptureBelowGet.PNG

 

In the Leave days the value it shows is 4 which is correct.

 

CaptureLeaveD.PNG

Super User
Super User

Re: Leave request flow with sharepoint

@Julien2 

Before doing anything else, please change the BalanceofAnnual column to a number with no decimals and test again.  If you still have an issue, please follow steps below.

__________________________________________________________

 

OK - thanks - I need just a little more help.  Open the run again and click on the actions in the apply to each action after the Get items action.

In the action where you set the leave balance variable, what is the value?

Take a look at the update item action - what value is shown for BalanceofAnnual?

What I need for you to do is to look at that part of the run and see what doesn't look quite right - then we can fix.  Make sense?

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Julien2
Level: Powered On

Re: Leave request flow with sharepoint

@ScottShearer 

 

I changed BalanceofAnnual column type to number and i test it but nothing happens.

 

When i open the run history to check for the values of  Leave balance and BalanceofAnnual those both actions are not clickable to check for the values no idea why.

 

CaptureNotclickable.PNG

 

Thank you!

Super User
Super User

Re: Leave request flow with sharepoint

@Julien2 

The issue must be that you aren't getting anything returned by Get Items - that may mean that there is an issue with your OData filter.

In my case, my the person or group column in the dashboard list is EmployeeName. 

Here is my Filer query:

PGOdata.jpg

 

To make this work:

  • My logic assumes that the person who put in the request for leave is the person who is getting the leave - in other words one person cannot enter a leave request for someone else
    • Make sure that the person who entered the leave request has an entry in the dashboard
  • verify that the employee name column in the dashborad list is a person or group column.
  • Create another test Flow with a button and add a get items action for the dashboard list like you did earlier.
    • Make sure that you are referring to the column exactly as it shows in the body
  • Note that I put /EMail after the column name - this is required
  • Make sure that you have single quotes around the column reference as in my screen shot

Please test and let me know how it goes.

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Julien2
Level: Powered On

Re: Leave request flow with sharepoint

@ScottShearer 

Waiting for you, take your time. Thank you !

Julien2
Level: Powered On

Re: Leave request flow with sharepoint

Hello again !! @ScottShearer 

 

Yes the problem that i was missing /EMail after the column name in OData filter. Now the BalanceofAnnual column is working perfectly.

 

Last question is it possible to update the AmountofAnnualLeave column in the dashboard to show the Leaving Days requested by the Employee when the request is approved?

 

For example:

  • If an Employee requested 2 days the first time and the request is approved can we update automatically the AmountofAnnualLeave to 2.
  • Again if the same employee requested 3 days the second time and the request is approved the AmountofAnnualLeave will be 2-3.. by - seperated.

How it should be:

CaptureAmount.PNGThank you!!

Super User
Super User

Re: Leave request flow with sharepoint

@Julien2 

In my example, the Amount of Annual Leave column is a string with a default value of None.

I added anothe string variable at the top of my flow called Leave History. 

I set the Leave History variable to the value of AmountofAnnualLeave after the Get items action.

The expression that I used to update the Amount of Annual Leave column in the update items action is:

if(equals(variables('Leave History'),'None'),variables('Leave Days'),concat(variables('Leave History'),'-',variables('Leave Days')))

LeaveExpression.jpg

 

 

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Julien2
Level: Powered On

Re: Leave request flow with sharepoint

@ScottShearer 

 

I followed your steps and it works well. But the problem is it shows first the (-), then the number of days it should look like 1 then 1-2 not -2-1..

 

Screenshot what i mean and how it shows:

Capture-.PNG

 

So how it should look like the expression for it shows (1-2-3...).

 

Thank you!

Super User
Super User

Re: Leave request flow with sharepoint

@Julien2 

The default value of Amount of annual leave in my example is None.  Set the column to None and try again.  Also, set the column default value to None.

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Julien2
Level: Powered On

Re: Leave request flow with sharepoint

@ScottShearer 

 

The flow works well.

 

Thank you very much for your time. I really appreciate your help. 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 429 members 5,342 guests
Please welcome our newest community members: