How to Append TimeStamp

Charles Fredie
Tera Contributor

When we post comments on SCTASK, they get copied to the RITM Additional comments as,
2024-08-07 10:15:00 - Author Name (Additional Comments) fix is in progress

Is there a way to do this?

1 ACCEPTED SOLUTION

Just wanted to make sure you weren't already doing something extra that I was about to undo.  This should do that:

(function executeRule(current, previous /*null when async*/ ) {
    var gr = new GlideRecord('sc_task');
    gr.addQuery('request_item', current.request_item);
    gr.query();
    while (gr.next()) {
        var comment = current.comments.getJournalEntry(-1);
        var usrstrt = comment.indexOf(" - ");
        var usrend = comment.indexOf(" (Additional");
        var usrname = comment.substring(usrstrt+3, usrend); //isolate the user Name
        var usrGr = new GlideRecord('sys_user');
        if (usrGr.get('name', usrname)) {
		    var tz = '"' + usrGr.time_zone + '"';
		    comment = comment.replace(' - ', ' ' + tz + ' - '); //update the comment with "author's timezone"
	    }
        gr.comments = comment;
        gr.update();
    }
})(current, previous);

 

View solution in original post

11 REPLIES 11

Hi  @Brad Bowman

var comment = current.comments.getJournalEntry(1);

Using this is not appending the latest comment right after the existing detail, the latest comment is getting copied to the last,
Check the SS attached, the latest comment with 'C' appends at the last, this should be on top, right after 'Testing', can you share your thoughts on that?latest.PNG

Since the comments are added one at a time, the existing Details changes with each update.  After comment A is added the existing Details is Testing..... (Additional comments) A, so appending the next comment to the existing Details is adding it to the end.  If you want the insertion point for the comment to be before a line that starts with a date, or maybe easier would be contains '(Additional comments)' you would have to incorporate this into desc in your script, splitting it into two different variables so that newDet = desc1 + comment + desc2.