How to get response back from slack in servicenow ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 04:11 AM
I have a request to send approval request to slack which shows two buttons i.e "Accept" and "Reject". When user click on that button response should send back to service now and corresponding request should be updated with response and comments will be updated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2024 12:10 AM
To implement this, you would need to use ServiceNow's Outbound REST Message functionality to send the approval request to Slack, and then use Slack's Interactive Messages feature to send the response back to ServiceNow. Here are the steps:
1. Create an Outbound REST Message in ServiceNow to send the approval request to Slack:
- Navigate to System Web Services > Outbound > REST Message.
- Click New to create a new REST Message.
- Fill in the necessary fields, such as Name, Endpoint, HTTP Method etc.
- In the HTTP Request field, include the necessary JSON payload to create the buttons in Slack.
2. In Slack, enable Interactive Messages:
- Navigate to your app settings page.
- Click on Interactive Messages in the left sidebar.
- Set the Request URL to the endpoint in ServiceNow that will receive the responses.
3. In ServiceNow, create a Scripted REST API to receive the responses from Slack:
- Navigate to System Web Services > Scripted REST APIs.
- Click New to create a new API.
- Fill in the necessary fields, such as Name, API ID, etc.
- In the Resources related list, click New to create a new resource.
- In the Script field, write a script to update the request with the response and comments.
4. In the script, you would need to parse the incoming JSON payload from Slack, extract the necessary information (such as the response and comments), and then update the corresponding request.
Here is a sample code snippet for the script:
javascript
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// Parse the incoming JSON payload
var body = request.body.data;
var payload = JSON.parse(body.payload);
// Extract the necessary information
var response = payload.actions[0].value;
var comments = payload.actions[0].selected_option.text.text;
// Update the corresponding request
var gr = new GlideRecord('sc_request');
if (gr.get(payload.callback_id)) {
gr.comments = comments;
if (response === 'Accept') {
gr.state = 'approved';
} else if (response === 'Reject') {
gr.state = 'rejected';
}
gr.update();
}
})(request, response);
Please note that this is a simplified example and you may need to adjust it according to your specific requirements.
nowKB.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2024 01:27 AM
Sure, here are the steps you can follow to achieve this:
1. Create a Slack App: You need to create a Slack app and enable interactive components. You can do this from the Slack API dashboard.
2. Enable Interactive Components: In the Slack app settings, enable Interactive Components. This will allow you to create buttons in your messages.
3. Create a Request URL: You need to create a Request URL in ServiceNow that Slack can send the responses to. This URL should point to a REST API in ServiceNow that can handle the responses.
4. Create a REST API in ServiceNow: You need to create a REST API in ServiceNow that can handle the responses from Slack. This API should be able to parse the payload from Slack and update the corresponding request in ServiceNow.
5. Update the Request: In the REST API script, you need to update the corresponding request in ServiceNow based on the payload from Slack. You can use the GlideRecord API to do this.
6. Send the Approval Request to Slack: You can use the Slack API to send the approval request to Slack. The message should include the buttons for "Accept" and "Reject".
7. Handle the Button Clicks: When a user clicks on a button in Slack, Slack will send a payload to the Request URL you specified. Your REST API in ServiceNow should be able to handle this payload and update the corresponding request.
8. Update the Comments: In the REST API script, you also need to update the comments of the request based on the user's response. You can use the GlideRecord API to do this.
Here is a sample code for the REST API in ServiceNow:
javascript
var gr = new GlideRecord('table_name');
gr.addQuery('sys_id', request.sys_id);
gr.query();
if (gr.next()) {
gr.u_status = request.status; // update the status
gr.u_comments = request.comments; // update the comments
gr.update();
}
Please replace 'table_name' with the actual table name, 'request.sys_id' with the sys_id from the Slack payload, 'request.status' with the status from the Slack payload, and 'request.comments' with the comments from the Slack payload.
nowKB.com
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/
For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER