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

How to insert image in notification via client script?

g_eggidio
Kilo Contributor

Hi all,

I have to insert an image in a notification. However, the image changes according to some data.
How can I insert the image via a client script? So to do a script check that depending on some data takes an image. Only the src will change.

1 ACCEPTED SOLUTION

Daniele Songini
Tera Guru

Hi,
create a script e-mail like this

(function runMailScript(current, template, email, email_action, event) {

	var image = '';

	if( /*condition*/ )
		image = 'image1.png';	
	else
		image = 'image2.png';	

	template.print( '<img src="' + image + '" />' );

})(current, template, email, email_action, event);

Please mark this as "Correct Answer" if I have given you a sufficient answer to your question.

Best Regards,
Daniele

View solution in original post

3 REPLIES 3

Saikiran Gudur1
Mega Guru

Hi there,

You need to use email scripts for that purpose.

In the email script evaluate your conditions and go with if else evaluations inside which you can print this content into template.

<p><img src="/10Things06a.png" width="513" height="334" /></p>

Where the image name changes in the evaluations (different images).

https://community.servicenow.com/community?id=community_question&sys_id=131b83eddb5cdbc01dcaf3231f96...

Thanks,
Saikiran Guduri (NOW)
Associate Certificate Engineer | ServiceNow Store Apps
(Please mark the answer as correct answer/helpful/accept the solution if it helps)

Daniele Songini
Tera Guru

Hi,
create a script e-mail like this

(function runMailScript(current, template, email, email_action, event) {

	var image = '';

	if( /*condition*/ )
		image = 'image1.png';	
	else
		image = 'image2.png';	

	template.print( '<img src="' + image + '" />' );

})(current, template, email, email_action, event);

Please mark this as "Correct Answer" if I have given you a sufficient answer to your question.

Best Regards,
Daniele

Hi,

Can I put a URL link or mail script link behind that image?

So if I had an image saying 'Make a comment' can I have the URL to take them to the portal on the current record when clicking on that image?

Thanks,

Stacy