Adding survey URL to incident resolution email notification

adrianps
Kilo Expert

I'm not sure if I've uncovered a bug...

I've created a Survey that is triggered when an incident is resolved, and I'd like to include the URL of the survey in the incident resolution email that is sent to the Caller.

I found an email notification script that, at face value, retrieves/constructs the URL for insertion into the email: incident_survey.  When I use this, however, the URL returned is incorrect.  I get "https://instancename.service-now.com/1"

After a bit of searching I found a solution where the incident_survey script was modified to use a function from the AssessmentUtils script include (https://community.servicenow.com/community?id=community_question&sys_id=dd5f6b73db8927408e7c2926ca9619af&anchor=answer_55eca084dbd1a340f7fca851ca9619fd&view_source=searchResult).

Specifically, it executes the following line to create the URL:

var link = new AssessmentUtils().getAssessmentInstanceURL(current.sys_id);

This solution also does not create a well-formed URL.

Digging deeper into the getAssessmentInstanceURL function, I suspect the problem is the way in which the parameter is consumed.

	// Survey Instance Table URL
	getAssessmentInstanceURL : function(/* String */instance) {
		var gr = new GlideRecord("asmt_assessment_instance");
		var type = '';
		if (gr.get(instance)) {
			var asmtRec = new GlideRecord("asmt_metric_type");
			asmtRec.addQuery("sys_id", gr.getValue("metric_type"));
			asmtRec.query();
			if (asmtRec.next())
				type = asmtRec.getValue("sys_id");
		}
		var instanceURL = gs.getProperty("glide.servlet.uri");
		var overrideURL = gs.getProperty("glide.email.override.url");
		var url = "";
		if(this.redirectToPortal() == 'true'){
			if(asmtRec.allow_public)
				url = instanceURL + this.defaultServicePortal + '?id=public_survey&instance_id='+instance;
			else
				url = instanceURL + this.defaultServicePortal + '?id=take_survey&instance_id='+instance;
		}
		else{
			if (overrideURL)
				instanceURL = overrideURL;
			else
				instanceURL = instanceURL + "nav_to.do";

			url = instanceURL + '?uri=assessment_take2.do%3Fsysparm_assessable_type=' + type + '%26sysparm_assessable_sysid=' + instance;
		}
		
		return url;
	},

The issue seems to be with using the 'instance' parameter (which I believe is a sys_id from the task table), as a key into the 'asmt_assessment_instance' table (i.e. the "if( gr.get(instance))" statement on line 5 above).  If I'm reading this correctly then this search will never return a record.

So at this point there are a couple of possibilities:

  1. I'm using the email notification script incorrectly
  2. There is a bug in the function above

If the function above is incorrect, then I presume the instance parameter should instead be used to search the asmt_assessment_instance table on the task_id field.  If that's the case, do I also need to filter for assessment instances that are active?  Is it possible for there to exist multiple assessment instances for a single task_id? Would additionally filtering by state resolve this?

I'm open to suggestions.

Cheers,

Adrian

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

The email you are sending must come from the Assessment table.
At the time a resolution email from incident fires, the Assesment record doesn't exist yet.

Your options are:

  • Re-engineer your Incident Resolution email to fire from the Assessment Instance table, and make it look like an Incident Resolution email
  • Modify the Service Portal Survey page to search for an assessment by record sys_id. By the time the User receives the email and clicks the link, the Assessment record will exist.

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

5 REPLIES 5

Matthew Bernard
Kilo Contributor

I would like to add a simple Thumbs up or Thumbs down on the Resolution notification instead of providing a link to send the customer to a survey.  Is this even possible?