Send ServiceNow Surveys to Microsoft teams chat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 10:57 PM
Gathering employee feedback through internal surveys is crucial. But maximising response rates can be a challenge. This article explores how instant messaging (IM) (Microsoft Teams) can be a powerful tool for boosting survey participation than traditional Email channel.
Solution Design
- Record update action will trigger survey assessment based on the trigger condition in ServiceNow
- ServiceNow flow will call MS power automate flow to send survey assessment card to the user in MS teams chat
- User responds with survey answers , Power automate flow call ServiceNow web service to update the survey answers
Implementation steps:
ServiceNow side
Step 1:
- Create a 'Survey' in survey designer and Survey trigger condition.
- View your survey and note down the Questions (asmt_metric) sys_ids , These values are required to update survey answers
Ex:
Step 2:
Create a Flow
- Trigger condition (same as survey trigger condition on current record)
- Lookup Record action - to get the triggered survey assessment instance sys_id
Table : asmt_assessment_instance
Condition: Trigger_id = current record sysID - Create a flow action - This action will send current task record data and sys_id of assessment instance created to Microsoft Power automate flow.
- create inputs to the flow action from flow (Task record and Assessment instance record from above action)
-create JSON payload to for request body for power automation flow
Ex: I am passing story record information like below- Create a script action - to call Microsoft Power automate flow web service (api will be generated by power automate flow 'When an HTTP request is received' trigger used - Refer Step 4)
Step 3:
Create a Scripted REST API with 'PATCH' HTTP method resource. - This will will receive survey response from MS power automation flow , we need to parse the request body to update the survey responses in the assessment questions.
Expected request payload for this function be like below.
{
"assessinsta": "assessment insstance ID", \\ Assessment instance sys_id
"srvyResponse": {
"99cfa3cf1b1d8ad467882060604bcb45": "Survey answer1",\\ metric sys_id of the question noted in the STEP 1
"f1cfa3cf1b1d8ad467882060604bcbdb": "Survey answer2",
"69cfa3cf1b1d8ad467882060604bcb8c": "Survey answer3",
"bdcfe3cf1b1d8ad467882060604bcb0a": "Survey answer4"
}
}REST API function script
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var reqBdy = request.body.dataString;
var repObj = JSON.parse(reqBdy);
//parse body and update assessment questions
for (key in repObj.srvyResponse) {
var qrString = "instance=" + repObj.assessinsta + "^metric =" + key;
var grAAIQ = new GlideRecord('asmt_assessment_instance_question');
grAAIQ.addEncodedQuery(qrString);
grAAIQ.query();
if (grAAIQ.next()) {
if (grAAIQ.metric.datatype == 'string') {
grAAIQ.string_value = repObj.srvyResponse[key];
}
grAAIQ.value = repObj.srvyResponse[key];
grAAIQ.update();
}
}
//complete assessment instance
var grAAI = new GlideRecord('asmt_assessment_instance');
grAAI.get(repObj.asin);
grAAI.state = 'complete';
grAAI.update();
var result = {};
result.message = 'updated in assessment :';
return result;
})(request, response);
Above 3 steps will complete servicenow side tasks
Microsoft Power Automate platform
Step 4:
Create a flow
- Add the following elements:
- Trigger:
- Choose When an HTTP request is received.
- Configure the trigger to accept POST requests and define a schema that matches the JSON payload structure from ServiceNow's Flow action (refer to step 3).
- Adaptive Card:
- Use Adaptive Cards Designer: https://adaptivecards.io/designer/ to create a card that presents the survey questions to the user.
- Ensure the card's response schema aligns with the expected format for updating ServiceNow assessment questions (Refer Step 1).
Ex: Question answer values should match the card answer values - Post to a chat or channel: (Optional)
- Use this action to send the Adaptive Card to the caller's chat for interaction.
- Extract the recipient's email from the trigger's output (if applicable).
- Parse JSON:
- Parse the user's responses from the Adaptive Card using the Parse JSON action.
- Extract the relevant answer data using a content expression like body('your_adaptive_card_name')['data'].
- HTTP request:
- Call the ServiceNow Scripted REST API using the following details:
- Method: POST
- URI: The URI of your Scripted REST API function (refer to step 3)
- Headers: Include an Authorization header with the value x-sn-apikey: <your_API_token> (replace with your generated API token)SpoilerServicenow instance should be in Washington DC version ,To generate REST API token based authentication
Alternatively you can use authorisation header with encode userid/password - use Postman tool to generated encoded string - Body: Request Payload same as Step 3
Add your questions in the comments , hit like if it is helpful for you.
Thanks - Aravinda
- 6,103 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
This article is very detailed and easy to understand. Thanks for documenting it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @Aravinda YS ,
i'm unable to process step 2 part-
Create a flow action - This action will send current task record data and sys_id of assessment instance created to Microsoft Power automate flow.
- create inputs to the flow action from flow (Task record and Assessment instance record from above action)
-create JSON payload to for request body for power automation flow
Here what information we need to take as input and need to pass in JSON payload?
Please provide information i'm stuck at this point.
Thanks!!
