Skip to content

Commit f9957be

Browse files
authored
Exclude date time from comments (#1167)
* Create findTableSize.js This script will help to get an idea of the size of tables present in ServiceNow instance and accordingly plan to reduce the instance database footprint. * commentsWithoutDateTime.js This email script is designed to extract and format the most recent comments from the current record in ServiceNow, while removing the username and timestamp typically associated with journal entries. * readme.md * Delete Background Scripts/findTableSize.js
1 parent 4ed2443 commit f9957be

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(function runMailScript(current, template, email, email_action, event) {
2+
3+
current.comments.getJournalEntry(1).match(/\n.*/gm).join('').replace(/^\s*\n/gm, ""); //getting the comments without the username,date/time
4+
5+
})(current, template, email, email_action, event);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//Retrieves the most recent comment (journal entry) from the comments field of the current record.
2+
//We can call this notification email script in notifications to get the comments only excluding the name, date/time details.
3+
4+
current.comments.getJournalEntry(1)
5+
//Extracting the Comment's Content (Removing Username/Date/Time):
6+
7+
.match(/\n.*/gm)
8+
//Matches all text after the first newline (\n). In ServiceNow, journal entries typically start with a username, date, and time stamp followed by the comment text. This regex targets everything after the first line, effectively bypassing the username and timestamp.
9+
10+
11+
.join('')
12+
//Joins the matched lines back into a single string. The empty string ('') is used to remove any newlines in the matched parts.
13+
14+
15+
.replace(/^\s*\n/gm, "")
16+
//This removes any leading empty lines (^\s*\n) or unnecessary whitespace that may remain after removing the username/timestamp, ensuring the comment starts cleanly with actual content.
17+
18+
19+
Result: The final output is the content of the most recent comment without the username, date, or time. This is useful for including clean, user-entered content in an email notification, without system-generated metadata like when the comment was added or who added it.

0 commit comments

Comments
 (0)