The CreatorCon Call for Content is officially open! Get started here.

How can I create a link in an email notification for assign to me?

chrisperry
Giga Sage

I am sending an email notification to a single user about an incident being assigned to their group.  In the email notification, I am looking to include a link that will allow the user to click on it and have the specified incident assigned to them.

I have read that I might be able to use Processors for this requirement, but I am not at all familiar with creating/using processors.  Any help is much appreciated!

 

Thanks,
Chris

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry
1 ACCEPTED SOLUTION

I got this to work on my PDI

HTML

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g2:evaluate var="jvar_unwrapped_url" jelly="true">
		var currentUser = gs.getUserID();
		var incidentFromURL = RP.getParameterValue('incident');
		var link = '';
		var incident = new GlideRecord('incident');
		if(incident.get('number', incidentFromURL)) {
			incident.setValue('assigned_to', currentUser);
			incident.update();
			gs.addInfoMessage(incident.getDisplayValue() + ' has been updated.');
			//gs.sendRedirect(incident.getLink());
			link = incident.getLink();
		}
		link || 'incident.do?sysparm_query=number=' + incidentFromURL;
	</g2:evaluate>
  ${gs.getMessage("Redirecting to your the incident")}...
</j:jelly>

Client Script

document.location.href = "$[JS:jvar_unwrapped_url]";

 

Link to the page with a url like /i.do?incident=INC12345

View solution in original post

9 REPLIES 9

Thank you so much, Jace!  This is super close, the only issue I am running into now is getting the UI page to automatically redirect to the incident record.  The assign to logged in user piece is working perfectly, but the redirect isn't working.

I have tried:

  • gs.redirect(link)
  • gs.setRedirect(link)
  • response.sendRedirect(link)

But none of the above are working, it just stays on the UI page's URL w/ a blank page, any ideas?

find_real_file.png

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

Maybe we are overthinking this.

Maybe we ought to set the redirect in the html after the g:eval

<script>
var params = new URLSearchParams(location.search.slice(1));
params.get('id')
var url = '/incident.do?sysparm_query=number=' + params.get('incident');
window.location = url;
</script>
 

Getting closer still... the redirect is now happening, but it seems that 'params.get('incident');' is returning null in the url, which brings me to this URL w/ info message of 'Record not found': https://ceidev.service-now.com/nav_to.do?uri=%2Fincident.do%3Fsysparm_query%3Dnumber%3Dnull

Here is the script I am now using based on your last response:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g:evaluate>
		var currentUser = gs.getUserID();
		//var incidentFromURL = RP.getParameterValue('incident');
		var incidentFromURL = 'INC0228551';
		var link = '';
		//expects url of /uipage.do?incident=INC12345
		var incident = new GlideRecord('incident');
		if(incident.get('number', incidentFromURL)) {
			incident.setValue('assigned_to', currentUser);
			incident.update();
			//link = 'incident.do?sys_id=' + incident.sys_id;
		}
		//gs.addInfoMessage('link is: ' + link);
		//gs.redirect(link);
	</g:evaluate>
	<script>
		var params = new URLSearchParams(location.search.slice(1));
		params.get('id');
		var url = '/incident.do?sysparm_query=number=' + params.get('incident');
		window.location = url;
	</script>
</j:jelly>
If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

I got this to work on my PDI

HTML

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g2:evaluate var="jvar_unwrapped_url" jelly="true">
		var currentUser = gs.getUserID();
		var incidentFromURL = RP.getParameterValue('incident');
		var link = '';
		var incident = new GlideRecord('incident');
		if(incident.get('number', incidentFromURL)) {
			incident.setValue('assigned_to', currentUser);
			incident.update();
			gs.addInfoMessage(incident.getDisplayValue() + ' has been updated.');
			//gs.sendRedirect(incident.getLink());
			link = incident.getLink();
		}
		link || 'incident.do?sysparm_query=number=' + incidentFromURL;
	</g2:evaluate>
  ${gs.getMessage("Redirecting to your the incident")}...
</j:jelly>

Client Script

document.location.href = "$[JS:jvar_unwrapped_url]";

 

Link to the page with a url like /i.do?incident=INC12345

chrisperry
Giga Sage

Thanks so much, Jace!  Worked like a charm - I really appreciate your help!!!

-Chris

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry