Is there a way to get the timestamp in a script when user post some comment in "Journal entry" field. e.g: work notes on Incident.

Sulabh Garg
Mega Sage
Mega Sage

Use case - we need to know the timestamp when support user posted the comments in work notes. we may have multiple comments so I want to understand how we can capture the timestamp for multiple comments through script.

 

I know we can store the timestamp in custom field through BR but thats not what I am looking for.

Please Mark Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg
1 ACCEPTED SOLUTION

lasse3
Mega Guru

All comments are stored in the sys_journal_field table. You can get the timestamp from this table.

Go to the table "sys_journal_field"

Filter on:

 Name = "the table the comments belong to, eg. incident"

 Element = "comments"

 Element Id = "The sys_id of the record that you wish to get the comments for"

The use the "sys_created_on" field as the timestamp for when the comment was created.

 

View solution in original post

3 REPLIES 3

lasse3
Mega Guru

All comments are stored in the sys_journal_field table. You can get the timestamp from this table.

Go to the table "sys_journal_field"

Filter on:

 Name = "the table the comments belong to, eg. incident"

 Element = "comments"

 Element Id = "The sys_id of the record that you wish to get the comments for"

The use the "sys_created_on" field as the timestamp for when the comment was created.

 

asifnoor
Kilo Patron

Hello Sulabh,

AS Lasse already mentioned, you can get the created date from sys_journal_field table.

using script, when you use getJournalEntry, it gives you the timestamp along with the comment.

gr.work_notes.getJournalEntry(), 

or

gr.comments.getJournalEntry()

Mark the comment as a correct answer and helpful if this has answered your question.

Janel
Kilo Sage

Something like this?

gs.print(current.work_notes.getJournalEntry(1).split(' ')[0]+' ' +current.work_notes.getJournalEntry(1).split(' ')[1]);
*** Script: 2020-12-22 09:04:29

Here is the breakdown of that

var lastWorkNote = current.work_notes.getJournalEntry(1).split(' '); //Split the string at the spaces.  Now you have an array (comma separated list) you can join pieces together by index ([0], [1], etc.)
gs.print("lastWorkNote: " +lastWorkNote); //This is what it looks like now.
var timestamp = lastWorkNote[0] + ' ' +lastWorkNote[1]; //Now we can build the time stamp by taking [0] (date), adding a space, then taking [1] (time).
gs.print("Timestamp: " +timestamp);

This is what we started with:

*** Script: 2020-12-22 09:04:29 - FirstName LastName (Work notes)
I'm some work notes from a record!
Wheeee!
 

And this is after the split:

*** Script: lastWorkNote: 2020-12-22,09:04:29,-,FirstName,LastName,(Work,notes)
I'm,some,work,notes,from,a,record!
Wheeee!

And finally after we piece the timestamp back together:

*** Script: Timestamp: 2020-12-22 09:04:29