How to update image in message HTML in notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi,
I need to update image in notifications which is used in multiple notifications.
If I am trying to update below screen I can see.
But, I found the image source is from images table, there I am updated the image so that it will update all places wherever it is used.
But, I don't see the changes in notifications, previous image only i can see.
Please suggest how to update image in message HTML in notification
below is the sample.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hello @t venkatesh2 ,
Actually the image you are trying to insert or any ootb images are configure in Email Templates table "sysevent_email_template" so you will need to create a custom template like the image and input the data you required
This will results in this type of preview notification..
If my response helped mark as helpful and accept the solution..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited an hour ago
That's right. You have to add images separately in all the notifications. Probably, you can add an image in one of your notifications. You will get the sys_id of the image stored in the 'sys_attachment' table. You can use the same source link in your next notification.
If you don't want to repeat the same activity in every notification then better add an email template , add an image there in the template and use the same email template in the notifications where you have to add the image.
If my response has helped you , mark it as helpful and accept the solution.
Regards,
Nayan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
29m ago
Do this
-> open any 1 notification and search that HTML source code
-> then upload new image to images table
-> then use background script and replace the earlier name i.e. testing.pngx with new name
Something like this, please test
// ServiceNow GlideScript (Business Rule, Script Include, etc.) - Server-side safe
function replaceImageSrc(html, oldSrc, newSrc) {
var regex = new RegExp('src="' + oldSrc + '"', 'g');
return html.replace(regex, 'src="' + newSrc + '"');
}
// Usage example
var gr = new GlideRecord("sysevent_email_action");
gr.addEncodedQuery("message_htmlLIKEtesting.pngx"); // search those notifications which use that img name
gr.query();
while (gr.next()) {
var updatedHtml = replaceImageSrc(gr.message_html.toString(), 'testing.pngx', 'new_image.png'); // give old image name and new image name
gs.info(updatedHtml);
gr.message_html = updatedHtml;
gr.update();
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
