As more and more organizations move towards remote work, communication and collaboration tools have become essential for seamless and efficient workflows. Microsoft Teams is one such tool that allows teams to communicate, collaborate, and stay productive from anywhere. Teams Approvals is a feature within Microsoft Teams that enables users to create, manage, and track approvals directly within Teams. On the other hand, ServiceNow is a powerful platform for managing workflows, incidents, and service requests. Integrating Teams Approvals with ServiceNow can streamline approval processes and improve overall efficiency.
There are different ways to implement this integration, in the first part of the post, we saw how we could integrate ServiceNow with Microsoft Teams Approvals to simplify the approval process for ServiceNow change requests.
In this second part of the post, we will explore how we can create a custom HTTP trigger in Power Automate to allow ServiceNow to trigger the approval process in Microsoft Teams. This will enable us to automate the approval process even further and integrate it with other systems that may not be directly connected to ServiceNow.
By the end of this post, you'll have a better understanding of how to integrate Microsoft Teams Approvals with ServiceNow and the benefits it can bring to your organization.
ServiceNow provides a free development environment called the Now Platform (https://developer.servicenow.com/dev.do), which enables developers to quickly build, test, and deploy applications to improve workflows and productivity within their organizations. With a free account on the Now Platform, you can start building powerful applications that leverage ServiceNow's advanced capabilities for workflow management, incident management, and service requests. Whether you're an experienced developer or just getting started, the Now Platform offers a flexible and easy-to-use environment for creating custom solutions tailored to your organization's unique needs.
Go to the Microsoft Teams website (https://www.microsoft.com/en-us/microsoft-teams/group-chat-software) and click on the "Sign up for free" button.
Enter your email address and click on "Next". If you already have a Microsoft account, you can sign in with that account.
Create a new password and click on "Sign up".
Follow the prompts to complete the setup process, such as entering your name and company information.
Once your account is set up, you can download the Microsoft Teams app on your desktop or mobile device and start collaborating with your team.
With a free Microsoft Teams account, you can chat with colleagues, make voice and video calls, share files, and collaborate on projects from anywhere. Plus, with its seamless integration with other Microsoft products, such as Office 365 and SharePoint, Microsoft Teams can help streamline your organization's workflows and improve productivity.
Microsoft provides a free Power Automate environment (https://powerautomate.microsoft.com/en-us/#home-signup), which enables users to automate workflows across multiple applications and services. With Power Automate, you can create automated processes, such as approvals, notifications, and data synchronization, to save time and increase efficiency. Whether you're a business user or a developer, the Power Automate environment provides an intuitive and easy-to-use interface for creating and managing workflows. Plus, with its seamless integration with other Microsoft products, such as Teams and SharePoint, Power Automate can help streamline your organization's workflows and improve collaboration.
First, ensure that you have a valid account for both Microsoft Teams and ServiceNow, as well as access to Power Automate.
This scenario is available in the first part of this post.
HTTP triggers are a powerful feature in Power Automate that allows us to create custom APIs and automate processes with external systems. By creating a custom HTTP trigger, we can make the approval process more flexible and scalable, and enable other systems to interact with Microsoft Teams Approvals without having to go through ServiceNow.
Here's a scenario on how to integrate Microsoft Teams Approvals with ServiceNow using Power Automate's scheduled trigger:
Open a web browser and go to the Power Automate portal.
Sign in to Power Automate using your Microsoft account or organizational account.
Once you're signed in, you should see the Power Automate portal dashboard. On the left-hand menu, click on "Create" to create a new flow.
Choose a template from the available options, or start from scratch by selecting "Instant - from blank".
To set up the "When a HTTP request is received" trigger, we need to define the input parameters that will be sent via a rule from ServiceNow (we will create this rule later).
{
"type": "object",
"properties": {
"sysapproval": {
"type": "string"
},
"sys_id": {
"type": "string"
},
"due_date": {
"type": "string"
},
"sys_created_by": {
"type": "string"
},
"approver": {
"type": "string"
},
"short_description": {
"type": "string"
},
"description": {
"type": "string"
},
"opened_by": {
"type": "string"
},
"approver_email": {
"type": "string"
},
"requestor_email": {
"type": "string"
},
"link_details": {
"type": "string"
}
}
}
The next step is sending the approval request to Microsoft Teams Approvals app.
Select Approve/Reject - Everyone must approve for the Approval type field.
Set up the mapping between the ServiceNow data fields and the corresponding fields in the Power Automate action:
Field | Value |
---|---|
Title | short_description |
Assigned to | approver_email |
Details | description |
Item link | link_details |
Item link description | ServiceNow more detail |
This action will update the corresponding approval records in ServiceNow with the latest information retrieved from Microsoft Teams.
In the Record Type field, make sure to select the second "Approval" item in the dropdown list, which corresponds to the "approval" table from production environment and not the first one which is for the staging environment.
In the System ID field, select the sys_id from the When a HTTP request is received step.
In the Comments field, select the Responses Comments from the Start and wait for an approval step.
In the State field, inform the value approved.
Note that when you save your trigger, you will be given a URL that you can use to invoke the trigger from external systems.
Business Rules are server-side logic that execute when database records are queried, updated, inserted, or deleted. For more details, please check the ServiceNow Business Rules documentation.
To set up a ServiceNow Business Rule to send a request to Microsoft Power Automate every time there is a new pending approval, you can follow these general steps:
Give the business rule a name and description that accurately describes its purpose. For example, MS Approvals.
Choose the table to which the business rule applies. This can be done by selecting the table from the drop-down menu in the "Applies to" field. For example, Approval [sysapproval_approver].
Specify the conditions that must be met for the business rule to run. This is done by adding conditions to the "When to run" section of the business rule. For example, you could specify that the rule should run after a new record is created or updated.
Add a filter condition to consider only pending approvals (state is requested).
It's important to note that creating a business rule in ServiceNow requires some knowledge of JavaScript and the ServiceNow platform. If you're not familiar with these concepts, it may be helpful to seek assistance from a ServiceNow administrator or developer.
Add the following code:
(function executeRule(current, previous) {
var snowURL = "https://dev128124.service-now.com/";
var sysapproval = current.getValue("sysapproval");
var approver = current.getValue("approver");
var openedBy;
var jsonTask ;
var jsonApprover ;
var jsonRequestor ;
//this isnt the best practice. Consider change it to oauth2 authentication
var user = 'CHANGE THIS VALUE';
var password = 'CHANGE THIS VALUE';
//GET TASK with the details of the pending approval
var taskRequest = new sn_ws.RESTMessageV2();
taskRequest.setBasicAuth(user,password);
taskRequest.setRequestHeader("Accept","application/json");
taskRequest.setRequestHeader('Content-Type','application/json');
taskRequest.setEndpoint(snowURL + "api/now/table/task?sysparm_query=sys_idIN" + sysapproval + "&sysparm_exclude_reference_link=true&sysparm_fields=number%2Cshort_description%2Copened_by%2Csys_id%2Cimpact%2Copened_at%2Cpriority%2Cdescription");
taskRequest.setHttpMethod("GET");
var responseTask = taskRequest.execute();
var taskBody = responseTask.getBody();
jsonTask = new JSONParser().parse(taskBody);
openedBy = jsonTask.result[0].opened_by;
//GET APPROVER EMAIL that will be used to send the card to Teams Approvals
var approverRequest = new sn_ws.RESTMessageV2();
approverRequest.setBasicAuth(user,password);
approverRequest.setRequestHeader("Accept","application/json");
approverRequest.setRequestHeader('Content-Type','application/json');
approverRequest.setEndpoint(snowURL + "api/now/table/sys_user?sysparm_query=sys_idIN"+ approver +"&sysparm_fields=sys_id,name,email");
approverRequest.setHttpMethod("GET");
var responseApprover = approverRequest.execute();
var approverBody = responseApprover.getBody();
jsonApprover = new JSONParser().parse(approverBody);
//GET REQUESTOR EMAIL that will be used on Teams Approvals card
var requestorRequest = new sn_ws.RESTMessageV2();
requestorRequest.setBasicAuth(user,password);
requestorRequest.setRequestHeader("Accept","application/json");
requestorRequest.setRequestHeader('Content-Type','application/json');
requestorRequest.setEndpoint(snowURL + "api/now/table/sys_user?sysparm_query=sys_idIN"+ openedBy +"&sysparm_fields=sys_id,name,email");
requestorRequest.setHttpMethod("GET");
var requestorResponse = requestorRequest.execute();
var bodyRequestor = requestorResponse.getBody();
jsonRequestor = new JSONParser().parse(bodyRequestor);
//CALL POWER AUTOMATE TO SEND TO TEAMS APPROVALS
try {
var body = {
"sysapproval": sysapproval,
"sys_id": current.getValue("sys_id"),
"due_date": current.getValue("due_date"),
"sys_created_by": current.getValue("sys_created_by"),
"approver": approver,
"short_description": "" + jsonTask.result[0].short_description,
"description": "" + jsonTask.result[0].description,
"opened_by": "" + openedBy,
"approver_email": "" + jsonApprover.result[0].email,
"requestor_email": "" + jsonRequestor.result[0].email,
"link_details" : snowURL + "now/nav/ui/classic/params/target/sysapproval_approver.do%3Fsys_id%3D" + current.getValue("sys_id")
};
var r = new sn_ws.RESTMessageV2();
// Change the following URL by the one you have created as HTTP trigger on Power Automate
r.setEndpoint("https://xxx.westus.logic.azure.com:443/workflows/xxxxxxxx56f6/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=EKb91O-VP86wsFeP144H63-vZHK8XFpcuu7HLHc7DEM");
r.setHttpMethod("POST");
r.setRequestBody(JSON.stringify(body));
r.setRequestHeader("Accept","application/json");
r.setRequestHeader('Content-Type','application/json');
var response = r.execute();
var httpStatus = response.getStatusCode();
} catch (ex) {
var message = ex.message;
gs.error("Error message: " + message);
}
gs.info("Webhook target HTTP status response: " + httpStatus);
})(current, previous);
In case you can't see any pending approval, consider removing the filter on the top of the page by clicking on All.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.