Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2019 03:44 AM
Hi,
Try this code and it should work.
var gr = new GlideRecord("incident");
gr.addActiveQuery();
gr.query();
while(gr.next()) {
var notes = gr.comments.getJournalEntry(-1);
var na = notes.split("\n\n"); //stores each entry into an array of strings
gs.print("Entered while loop"+notes);
for (var i = 0; i < na.length; i++) {
gs.print(na[i]);
gr.work_notes=na[i];
gr.update();
}
//now delete the additional comments. which we need to do from 3 tables sys_audit, sys_history_line,sys_history_set and sys_journal_field
var sysaudit_rec = new GlideRecord("sys_audit");
sysaudit_rec.addQuery("documentkey",gr.sys_id); //incident sys_id
sysaudit_rec.query();
while(sysaudit_rec.next()) {
//now fetch and delete associated history line records
var history_rec = new GlideRecord('sys_history_line')
history_rec.addQuery('audit_sysid',sysaudit_rec.sys_id);
history_rec.query();
if(history_rec.next()){
history_rec.deleteMultiple();
}
//fetch and delete entries from sys_history_set.
var historyset_rec = new GlideRecord('sys_history_set')
historyset_rec.addQuery('id',gr.sys_id); //incident sys_id
historyset_rec.query();
if(historyset_rec.next()){
historyset_rec.deleteMultiple();
}
sysaudit_rec.deleteMultiple();
}
var journal_rec = new GlideRecord("sys_journal_field");
journal_rec.addQuery("element_id",gr.sys_id); //incident sys_id
journal_rec.addQuery("element","comments");
journal_rec.query();
while(journal_rec.next()) {
journal_rec.deleteMultiple();
}
}
Mark the comment as a correct answer and also helpful once worked.