How to copy both work notes and additional comments in a field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 12:28 AM
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
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 01:28 AM
Hi Udhay,
I entered as below order
1. Additional Comments : comments1
2. Work Notes: notes1
3. Work Notes: notes2
4. Additional COmments : comments2
But the comments got updated as below
1. comments1
2. notes1
3. notes2
4. notes2 //again the last updated worknotes i.e notes2 instead of the latest additional comment i.e comment2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 01:39 AM
// Try this sample code
var additionalComments = '';
var workNotes = '';
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
if(current.comments.changes){
additionalComments = current.task.comments.getJournalEntry(1);
}else if(current.work_notes.changes){
workNotes = current.task.work_notes.getJournalEntry(1);
}else{
//Do nothing
}
if(additionalComments != ''){
current.comments = additionalComments.replace(dateRE, '');
}
if(workNotes != ''){
current.comments = workNotes.replace(dateRE, '');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 01:56 AM
In this case worknotes is not getting copied only additional comments is getting copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 02:08 AM
In which table you have written your business rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 02:10 AM
table :task_time_worked
when :before insert/update
Script:
var additionalComments = '';
var workNotes = '';
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
if(current.task.comments.changes()){
additionalComments = current.task.comments.getJournalEntry(1);
}else if(current.task.work_notes.changes()){
workNotes = current.task.work_notes.getJournalEntry(1);
}else{
//Do nothing
}
if(additionalComments != ''){
current.comments = additionalComments.replace(dateRE, '');
}
if(workNotes != ''){
current.comments = workNotes.replace(dateRE, '');
}