Custom preview email notification using OOB notification display ui page not working as expected

vishnu vandana2
Kilo Contributor

Hi All,

 

In one of our custom  UI action, We have used "notification_display" UI page to preview email by passing record sysid and notification sysid.

 

Till Jakarta it was working fine but after upgrading to Madrid it is not parsing the record sysid and is throwing a blank page on click of the UI action.

 

Please find the response for the same from Servicenow below:

 

**The custom UI Action you have in place for Preview Notification is calling a UI Page called notification_display which in turn loads a backend template notification_display.xml.

This backend template has changed considerably from the Jakarta release to the Madrid release and it does not use the 'sysparm_target_id' anymore to reference the record for which the notification is being generated. This template is used within the notification_preview.xml template which has also been modified to accommodate these changes.

 

This is why the custom UI Action implementation has stopped working from Jakarta to Madrid. The UI Page that you are using in your Ui Action is only intended to be used within the notification_preview page.

 

Please note that we cannot guarantee that any custom implementations will work across different versions of the platform.

 

You can try to use the notification_preview UI page in your UI Action to replicate the popup seen when previewing the notification from the notification record itself.**

 

As suggested by them we used "notification_preview" UI page and that inturn gives us a different layout, which we are not happy with

 

 

Has anyone faced this issue? suggestions are welcome

3 REPLIES 3

chadto
Tera Contributor

I have pretty much the same problem, and while I am also trying to figure out some way to pass the sysparm_target_id parameter into notification_display, in the meantime, I am trying to settle for the notification_preview UI Page. That page doesn't even seem to have a parameter to pass the record info in, do you know what it might be?

xavier_robert
Tera Expert

Hi Vishnu,

We have the same issue. We follow the following steps to resolve it.

1- Create an ui macro :

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
		<script src="scripts/heisenberg/heisenberg_all.js" />
	<g:requires name="styles/heisenberg/heisenberg_all.css" includes="true" />
	<g:requires name="notification_preview.css" includes="true" />
	<script src="scripts/lib/jquery_includes.js" />
	<j2:if test="$[!jvar_isMSIE8 &amp;&amp; !jvar_isMSIE7 &amp;&amp; !jvar_isMSIE6]">
	<g:evaluate jelly="true"> 
		var emailAction = new GlideRecord("sysevent_email_action");
		emailAction.query("sys_id", jelly.sysparm_notification_id);
		emailAction.next();
		var tableName = emailAction.collection;
	</g:evaluate>
    <base target="_blank" />	
	
	<h4 class="form_header"><strong>${gs.getMessage("Subject")}</strong></h4>
	<div id="simulated_subject" />
	
	<hr />
	
	<h4 style="position:relative" class="form_header">
	<j:if test="${emailAction.content_type == 'multipart/mixed'}" >
		<select id="content_type" class="form-control" name="content_type" onchange="contentTypeSwitch(this.value)">
			<option>HTML</option>
			<option>Plain Text</option>
		</select>
	</j:if>
	<strong>${gs.getMessage("Body")}</strong></h4>
	<div id="simulated_html" />
	<pre id="simulated_text" />
	<script>
		populate();
        

	    function populate(showAll) {	  
	    	if (typeof showAll == 'undefined')
	    		showAll=false;
	    	
			var record = "${sysparm_target_id}";
			var recordPickerElement = document.getElementById('record_picker');
			if (recordPickerElement)
				record =  recordPickerElement.value;
			
			var event = "";
			var eventPickerElement = document.getElementById('event_picker');
			if (eventPickerElement)
				event = eventPickerElement.value;
			
			var generation_type = $("generation_type");
			if (generation_type &amp;amp;&amp;amp; generation_type.value != "Existing Event")
				event ="";
				
			if (${emailAction.content_type == "text/plain"})
				contentTypeSwitch("Text Plain");
			else
				contentTypeSwitch("HTML"); 

			var ga = new GlideAjax("NotificationSimulator");
			ga.addParam('sysparm_name', 'simulate');
			ga.addParam('sysparm_record_id', record);
			ga.addParam('sysparm_event_id', event);
			ga.addParam('sysparm_email_action_id', '${sysparm_notification_id}');
			ga.addParam('sysparm_changed_fields','${sysparm_changed_fields}');
			ga.getXMLAnswer(populateHTML);
			
			function populateHTML(answer) {
				if (answer == null)
					return;
			    var jsonAnswer = JSON.parse(answer);
			    displayNotificationData(jsonAnswer);
			}
			
			function displayNotificationData(jsonAnswer) {
				$("simulated_subject").innerHTML = jsonAnswer.subject;
			    $("simulated_html").innerHTML = jsonAnswer.body;
			    $("simulated_text").innerHTML = jsonAnswer.body_text;
			}

		}
		
		function contentTypeSwitch(value) {
			var html = $("simulated_html");
			var text = $("simulated_text");
			if (value == "HTML") {
				html.show();
				text.hide();
			} else {
				html.hide();
				text.show();
			}
		}
		
	</script>
	</j2:if>

</j:jelly>

2- create an ui page

<?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:macro_invoke macro="your ui macro" />
</j:jelly>

3- modify your ui action

function showSimulator() {
	
	if (typeof rowSysId == 'undefined' || rowSysId == null)
		sysId = gel('sys_uniqueValue').value;
	else
		sysId = rowSysId;
	
	var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
	var dd = new dialogClass("alm_notification_display");
	dd.setTitle("Notification Preview");
	dd.setWidth(1000);
	dd.setPreference('sysparm_notification_id', g_scratchpad.sys_id_notification);
	dd.setPreference('sysparm_target_id', sysId);
	
	dd.render();
}

 

 

 

Hi Xavier,

 

We are using the code above and now running into issues in some cases where the script include NotificationSimulator is now returning blank. Have you run into any such issues? 

 

Thanks

Aman