Hello everyone! Today, I would like to share a brief example of automating the process of creating offboarding requests for new employees using Microsoft SharePoint, PowerApps, Power Automate, and Teams. Implementing this process will not require purchasing separate user plans for PowerApps and Power Automate; a subscription to Office 365 E1/E3/E5 will be sufficient. On the SharePoint site, we will create lists and columns, PowerApps will help create the form, and Power Automate will provide capabilities to configure business process logic. We will connect the final process to an MS Teams channel. Let's not waste time and see what comes of this.

In the first step, we create lists and attributes. We will need the following lists:
- Employee Offboarding Requests
- Departments
- HR by Departments
- Administrators
Each list will play its role, and we will see which one. We create attributes and configure the navigation menu:

PowerApps
Now, let's create a form for the 'Employee Offboarding Requests' list using PowerApps. In the final version, it will look like this:

In the 'Employee' field, you select from the list of Office 365 users, the 'Exit Date' is picked from the calendar, the 'Department' is chosen from the department reference, and 'HR' is selected from the 'HR by Departments' reference:

However, we need to ensure that the list of HR personnel available for selection is filtered based on the department specified in the form. We will use a formula to filter data in PowerApps. For the 'Items' property of the 'HR' field, we write:

Additionally, on the form, we can make a few adjustments to the default value for the Status field. For the 'Default' property of the Status field, we write:

If the item creation form is opened, the 'Status' field will be set to 'New'; otherwise, the status field on the form will be populated with the value from the SharePoint column for the current item.
One of the challenges with PowerApps is the difficulty in easily obtaining data from SharePoint groups. As a result, it becomes challenging to configure the visibility/accessibility of fields or objects on the form if you wanted to tie it to a user's membership in a SharePoint group. However, a workaround can be implemented. For this, we have already created a list of Administrators:

This list includes the field 'Employee' with the type 'User or Group', which is displayed only on the form, and the field 'Name', where the name of the selected employee is entered, displayed only in the list view. Now, let's perform a little trick in PowerApps. For example, you can configure the availability of any field based on the condition of the current user being in the Administrators list. We find the 'Display Mode' property of the 'Exit Date' field and write:

According to this formula, if there is at least one employee in the Administrators list whose login matches the current user's login, then the field will be available for editing; otherwise, it will be view-only. For greater reliability, we convert the login to lowercase, just in case.
You may have noticed that there is a button 'Actions on the Request' in the form header:

This button will navigate to another screen where, for convenience, all possible actions on the request are gathered:

After clicking each button, an additional action window opens; for example, if the action 'Cancel Request' is selected, an additional window opens allowing for comment input:

After clicking the 'Confirm' button, the request status changes, and this can even be done without starting a Power Automate flow. We will use the 'Patch' function for the 'OnSelect' property of the button:

Using the Patch function, we update the request list item, filtering it by the ID of the current item. We change the 'Status' field value and navigate back to the main screen. The logic is similar for the other action buttons.
Now we need to configure the approval flow. We'll do it in the simplest form.
Power Automate
Our approval flow will be triggered automatically upon the creation of a request. During execution, the request status will change, the head of the department will be obtained, and an email notification of the new request will be sent to the head. To identify the head, we have the 'Departments' directory:

Create a Power Automate flow:

During the execution of this flow, the head of the department receives an email notification about the creation of a new request and can click the link to make a decision by pressing the button:

Clicking the ‘Approve’ or ‘Reject’ button also triggers a Power Automate flow that changes the status of the application and sends an email notification to the HR specialist:

The process is ready.
Teams
And the final touch – organizing collaborative work on this process. For this, we connect the process to the MS Teams team:

Now, all team members in MS Teams have access to the new employee onboarding process on a separate tab.
Of course, the flow logic can accommodate multi-step approvals, plus there is the option to use the Approvals component for task assignments in Power Automate. You can also set up reports and create notifications that will be sent to the Microsoft Teams chat-bot. But more on that in future articles. Thank you for your attention and have a great day!
Source: habr.com
