Connect survey to incident trigger email

Patrick51
Giga Contributor

I'm trying to achieve a few things with a survey that will be sent out with an email that is triggered by an incident being resolved. Currently the email sent out redirects to a microsoft forms page. I would like this to redirect to a servicenow survey. The issue arises when a person fills out the first survey with the link:

https://<dev instance>.service-now.com/nav_to.do?uri=assessment_take2.do%3Fsysparm_assessable_type=cc3c5fbb4f2033008ff7b63ca310c732

This is just the view survey url from the survey portal. It works fine with having a trigger setup on the survey to automatically create a new assessment instance every time an incident resolves. This link will find that instance and have them take that one. My real problem comes from if a person was to click the link twice I want the survey to still link back to the original survey instance, but with the above link it will create a new survey, which is also not linked to an incident. This is expected behavior according to the documentation. So that is my question. Is there some way to have the link above redirect to the instance that is generated by the trigger when the notification is based off of the incident table. 

1 ACCEPTED SOLUTION

Patrick51
Giga Contributor

I think I found a solution that works for me but if anyone spots any weird errors in my code please let me know. Survey trigger goes off when an incident is resolved which creates a survey instance. The initial email goes out based on the incident table. In this email I created an email script

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

	var assessmentVar = new GlideRecord('asmt_assessment_instance');
 	assessmentVar.query();
	assessmentVar.addQuery("trigger_id", current.sys_id);
	assessmentVar.query();
 	if(assessmentVar.next()) {
		var link = new AssessmentUtils().getAssessmentInstanceURL(assessmentVar.sys_id);
		template.print(url);
 	}
	
 })(current, template, email, email_action, event);

Following the resolution of the incident a few days later the incident closes and another email goes out that is just about the survey request. What I like about this solution is it means no one can double up on surveys accidentally since the url points to the same instance in both cases. This way we hopefully can increase the response to surveys without getting duplicates.

Again if there is anything weird about my code let me know!

View solution in original post

3 REPLIES 3

Patrick51
Giga Contributor

I think I found a solution that works for me but if anyone spots any weird errors in my code please let me know. Survey trigger goes off when an incident is resolved which creates a survey instance. The initial email goes out based on the incident table. In this email I created an email script

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

	var assessmentVar = new GlideRecord('asmt_assessment_instance');
 	assessmentVar.query();
	assessmentVar.addQuery("trigger_id", current.sys_id);
	assessmentVar.query();
 	if(assessmentVar.next()) {
		var link = new AssessmentUtils().getAssessmentInstanceURL(assessmentVar.sys_id);
		template.print(url);
 	}
	
 })(current, template, email, email_action, event);

Following the resolution of the incident a few days later the incident closes and another email goes out that is just about the survey request. What I like about this solution is it means no one can double up on surveys accidentally since the url points to the same instance in both cases. This way we hopefully can increase the response to surveys without getting duplicates.

Again if there is anything weird about my code let me know!

Harsimrajeet Si
Kilo Contributor

Hi Patrick,

Thanks for sharing it. We have used it in our case and worked as expected.

However, in script, there is a correction:

 

template.print(url);

Instead of url in above line, it should be link.

regards 

Harsimranjeet Singh

hi harsimranjeet/patrick, ihave tried the same to share the survey link. but this is not working

var assessmentVar = new GlideRecord('asmt_assessment_instance');
assessmentVar.query();
assessmentVar.addQuery("trigger_id", current.sys_id);
assessmentVar.query();
if (assessmentVar.next()) {
var link = new AssessmentUtils().getAssessmentInstanceURL(assessmentVar.sys_id);
template.print(https://dev.service-now.com/nav_to.do?uri=assessment_take2.do%3Fsysparm_assessable_type=c61e17b51b6e60105cf40f6cdc4bcbd2);
}

 

it is showing error as " Javascript compiler exception: missing ) after argument list"

 

please help