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

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Try 

 

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 comment;

if(additionalComments){

 

comment = additionalComments.replace(dateRE, '')+'\n';

}
if(workNotes) {

comment+= workNotes.replace(dateRE, ''); 
}

current.comments = comment;

 

Note Untested code.

 

-Pradeep Sharma

Hello,

Try the below script:-

if(current.comments.changes())
	{
	current.description=current.comments.getJournalEntry(1);//change your field name.
	
	if(current.work_notes.changes())
		
	current.short_description=current.work_notes.getJournalEntry(1);//change your field name.
	
	
}

Regards,

Mohammed Iqbal

Hi Pradeep,

I did get this in the comment, I entered worknotes first.

find_real_file.png

Kamal17
Kilo Sage

Hi,

Try this code should solve your issue. It will set comments or worknotes based on the kind of info you are entering.

//Sample Code

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(current.comments.changes && additionalComments){

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

if(current.work_notes.changes && workNotes) {

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

-Regards,
Udhay