Copy journalentry without date and updated by
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2023 08:58 PM - edited 08-20-2023 09:01 PM
Hi
I'm copying all journal entry from one table to another using below code. But I don't want datestamp and updated by. Just want the comments to be updated. How to remove those?
var notes = gr.u_work_notes.getJournalEntry(-1);
current.comments = notes;
current.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2023 11:08 PM
Hi Mega,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 12:55 AM
I updated code as below, but it's just removing first line and not all.
var gr = new GlideRecord('kb_knowledge');
gr.addQuery('sys_id', current.document_id);
gr.query();
if (gr.next()) {
var work_notes_get_all = gr.u_work_notes.getJournalEntry(-1);
var na = work_notes_get_all.split(/\n\n(?=[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} - )/);
for (var i = 0; i < na.length; i++)
//gs.addInfoMessage(na[i].match(/\n.*/gm).join('').replace(/^\s*\n/gm, ""));
current.comments = na[i].match(/\n.*/gm).join('').replace(/^\s*\n/gm, "");
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 04:58 AM - edited 08-21-2023 04:59 AM
Hi Mega,
This is Working from below is the screen shot and script
Screen shot taken from Incident record

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 05:22 AM
Hello @Hafsa1,
To remove the datestamp and updated by from the journal entry, you can use a regular expression to match and replace the unwanted parts of the string.
A regular expression is a sequence of characters that defines a search pattern for text. You can use regular expressions in ServiceNow to manipulate strings using the String class methods.
//Get the last journal entry from the source table
var notes = gr.u_work_notes.getJournalEntry(-1);
//Create a regular expression to match the datestamp and updated by
var regex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} - .*\n/gm;
//Replace the matched parts with an empty string
var comments = notes.replace(regex, “”);
//Set the comments field in the target table to the modified string
current.comments = comments;
å //Update the target record
current.update();
This code will remove any lines that start with a datestamp in the format YYYY-MM-DD HH:MM:SS followed by a dash and any characters, and end with a newline character.
For example, it will remove lines like this:
2023-08-21 11:07:33 - John Smith
You can modify this code according to your needs and preferences.
Hope this helps.
Kind Regards,
Swarnadeep Nandy