
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2024 08:56 AM - edited 12-07-2024 08:58 AM
Hi,
I am writing Business Rules to Copy Work Notes from Problem to Incident. Description and Short Description work fine, but Work Notes is not working. Kindly help.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('incident');
gr.addQuery('problem_id', current.sys_id);
gr.query();
while(gr.next()){
gr.work_notes = current.work_notes;
gr.update();
}
})(current, previous);
Regards
Suman P.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2024 09:03 AM
Hi @Community Alums ,
Work notes are stored in activity table not in activity incident and problem directly so it work like normal fields, try below code,
// Ensure the Incident record exists
if (current.incident) {
var incident = new GlideRecord('incident');
if (incident.get(current.incident)) {
// Query the problem's work notes (sys_journal_field)
var workNotes = new GlideRecord('sys_journal_field');
workNotes.addQuery('table', 'problem');
workNotes.addQuery('document', current.sys_id);
workNotes.addQuery('type', 'comment'); // Make sure it's Work Notes, not just any comments
workNotes.query();
// Loop through each Work Note and copy to the Incident
while (workNotes.next()) {
var newWorkNote = new GlideRecord('sys_journal_field');
newWorkNote.initialize();
newWorkNote.table = 'incident';
newWorkNote.document = incident.sys_id;
newWorkNote.type = 'comment'; // Ensure it's set as a Work Note
newWorkNote.value = workNotes.value; // Copy the actual work note text
newWorkNote.insert();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2024 09:03 AM
Hi @Community Alums ,
Work notes are stored in activity table not in activity incident and problem directly so it work like normal fields, try below code,
// Ensure the Incident record exists
if (current.incident) {
var incident = new GlideRecord('incident');
if (incident.get(current.incident)) {
// Query the problem's work notes (sys_journal_field)
var workNotes = new GlideRecord('sys_journal_field');
workNotes.addQuery('table', 'problem');
workNotes.addQuery('document', current.sys_id);
workNotes.addQuery('type', 'comment'); // Make sure it's Work Notes, not just any comments
workNotes.query();
// Loop through each Work Note and copy to the Incident
while (workNotes.next()) {
var newWorkNote = new GlideRecord('sys_journal_field');
newWorkNote.initialize();
newWorkNote.table = 'incident';
newWorkNote.document = incident.sys_id;
newWorkNote.type = 'comment'; // Ensure it's set as a Work Note
newWorkNote.value = workNotes.value; // Copy the actual work note text
newWorkNote.insert();
}
}
}