Scripting Help- Link to Survey Results
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 11:42 AM
From an email notification, how can we add a link to view a survey response?
See attached for the survey results page we need to link to.
The email notification pulls from the 'Assessment Instance' table, triggered when an assessment records' metric is matched and the State of the assessment is complete.
Help is greatly appreciated!!
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 09:36 PM
Hi @Su522
To add a link in an email notification that allows the user to view a survey response in ServiceNow, you can include a dynamic URL pointing to the assessment or survey result page based on the Assessment Instance
(asmt_assessment_instance
) table.
Since the email notification is triggered when the state of the assessment is complete, you can dynamically generate the link to the survey response in the email. Typically, the URL format in ServiceNow to view a record looks like this:
https://<instance_url>/nav_to.do?uri=<table>.do?sys_id=<record_sys_id>
In your case, you need a link pointing to the asmt_assessment_instance
record where the survey responses are stored.
Sample Script for the Email Notification:
Here’s how you can construct the link to the survey results in the email:
- URL Template: You can construct the link using the
sys_id
of the assessment instance. - Email Notification: Add the URL to the email body, dynamically referencing the assessment instance's sys_id.
Example of the Link in the Email Notification Body:
<html>
<body>
<p>Hello,</p>
<p>The assessment for <strong>${assessment_name}</strong> has been completed. You can view the survey responses by clicking the link below:</p>
<p>
<a href="https://${gs.getProperty('glide.servlet.uri')}/nav_to.do?uri=asmt_assessment_instance.do?sys_id=${assessment_instance.sys_id}">
View Survey Response
</a>
</p>
<p>Thank you.</p>
</body>
</html>
Explanation:
${gs.getProperty('glide.servlet.uri')}
: This dynamically generates your instance's base URL.asmt_assessment_instance.do
: This directs the user to the Assessment Instance table form view.${assessment_instance.sys_id}
: This dynamically pulls thesys_id
of the assessment instance, linking to the specific survey response.
Steps to Add the Link in the Notification:
-
Create or Edit the Email Notification:
- Go to System Notification > Email > Notifications.
- Create a new notification or edit an existing one.
-
Set the Trigger Conditions:
- In your case, this is already set to trigger when the assessment is complete, so no need to change that.
-
Add the Link to the Email Body:
- In the notification’s email body, insert the HTML snippet shown above where you want the link to appear.
-
Test the Notification:
- Make sure to test it by completing an assessment and checking if the email correctly links to the survey response.
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.
********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect
Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 11:20 AM
@PrashantLearnIT Hi, I really appreciate your response, but this didn't work.
Can you please provide screenshots?
Maybe I'm not creating the URL Template correctly.
Thank you very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2024 09:49 AM
Any help on this please?
The solution offered did not work.
Help is much appreciated.
Thank you