This widget could not be displayed.
This widget could not be displayed.

How to copy both work notes and additional comments in a field

sk59
Tera Expert

Hi All,

We are using OOB Time Worked functionality on incident form So I would like to copy the latest Additional Comments /Work notes entered on Incident to comments field in Time worked table.

I wrote a before insert/update BR

var workNotes = current.task.work_notes.getJournalEntry(1);
var additionalComments = current.task.comments.getJournalEntry(1);
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;

if(additionalComments){

 

current.comments = additionalComments.replace(dateRE, '');}
if(workNotes) {

current.comments = workNotes.replace(dateRE, '');
}

 

But it is updating either work notes or comments 

If I first enter comments it is updating comments later if I enter worknotes it is still updating the last comments which i entered previously instead of the lates worknotes.

 

Please suggest where I am going wrong

 

17 REPLIES 17

I guess your requirement is to update time worked record with latest comments or worknotes from corresponding task whenever a time worked record is created or updated.

If this is your case then

1. Create a BR on Time Worked table with before update/insert. (guess you did that already)

2. Fetch the recent values of both additional comments and worknotes field from incident, concatenate and then update the string in comments field of the time worked record.

Note: We will not be able to identify the field (additional comments/worknotes) that got changed in incident table in the BR, since the BR runs in Time Worked table. So as far as i know it's always better to take both of the values and update them in comments field.

 

Mark Correct if this solves your issue. Hit Like/Helpful based on the impact.

-Regards,

Udhay

Could you please help with the script to concatenate both?

var workNotes = current.task.work_notes.getJournalEntry(1);
var additionalComments = current.task.comments.getJournalEntry(1);
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
var message = '';

if(additionalComments){

message = "Additional Comments: "+additionalComments.replace(dateRE, '');
}

if(workNotes) {

message = message+"\nWork Notes: "+workNotes.replace(dateRE, '');
 
}
current.comments = message;

Hi Uday,

I tried this and this is working fine if we enter additional comments first,

If we enter work notes first it is appending undefined to the worknotes

It was just a sample so i didn't test the code. So probably you can add conditions to handle these scenarios.

var workNotes = current.task.work_notes.getJournalEntry(1);
var additionalComments = current.task.comments.getJournalEntry(1);
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
var message = '';

if(additionalComments != '' && additionalComments != null && additionalComments != 'undefined' && additionalComments != undefined){

message = "Additional Comments: "+additionalComments.replace(dateRE, '');
}

if(workNotes != '' && workNotes != null && workNotes != 'undefined' && workNotes != undefined) {

message = message+"\nWork Notes: "+workNotes.replace(dateRE, '');
 
}
current.comments = message;