update/delete previous additional comments and worknotes on incident form

AishwaryaS1
Kilo Sage

I want to update or delete the previous comments in the activity log of the incident form using scripting.

Also, need to create a "Redact" button so onclick Redact we can update or delete the comments on the incident form.

Aishwarya Shelake
3 ACCEPTED SOLUTIONS

I need to do it using scripting, and also need to create a button for that on incident form

Aishwarya Shelake

View solution in original post

I need to do it using scripting, and also need to create a button for that on incident form

Aishwarya Shelake

View solution in original post

AishwaryaS1
Kilo Sage

For update and delete the comments from the activity log I used the following script which works for me.

 

// Delete History Sets
var historyGR = new GlideRecord('sys_history_set');
historyGR.addEncodedQuery('id=' + currentRecord + '^ORid=' + requestItem);
historyGR.query();
historyGR.deleteMultiple();

// Update the current record
grRecord.update();


// Redact audit
var commentsGR = new GlideRecord('sys_audit');
commentsGR.addEncodedQuery('documentkey=' + currentRecord + '^ORdocumentkey=' + requestItem);
commentsGR.query();
while (commentsGR.next()) {
var comments, comments1;
if (commentsGR.fieldname == 'work_notes' || commentsGR.fieldname == 'comments') {
comments = commentsGR.newvalue;
} else {
comments = commentsGR.oldvalue;
}
comments1 = commentsGR.newvalue;
if (comments.indexOf(redactString) !== -1 || comments1.indexOf(redactString) !== -1) {
var updatedComments = comments1.replaceAll(redactString, '[REDACTED]');
commentsGR.newvalue = updatedComments;
if (commentsGR.fieldname != 'work_notes' && commentsGR.fieldname != 'comments') {
commentsGR.oldvalue = '';
}
commentsGR.autoSysFields('false');
commentsGR.update();
}
}

Aishwarya Shelake

View solution in original post

6 REPLIES 6

AishwaryaS1
Kilo Sage

For update and delete the comments from the activity log I used the following script which works for me.

 

// Delete History Sets
var historyGR = new GlideRecord('sys_history_set');
historyGR.addEncodedQuery('id=' + currentRecord + '^ORid=' + requestItem);
historyGR.query();
historyGR.deleteMultiple();

// Update the current record
grRecord.update();


// Redact audit
var commentsGR = new GlideRecord('sys_audit');
commentsGR.addEncodedQuery('documentkey=' + currentRecord + '^ORdocumentkey=' + requestItem);
commentsGR.query();
while (commentsGR.next()) {
var comments, comments1;
if (commentsGR.fieldname == 'work_notes' || commentsGR.fieldname == 'comments') {
comments = commentsGR.newvalue;
} else {
comments = commentsGR.oldvalue;
}
comments1 = commentsGR.newvalue;
if (comments.indexOf(redactString) !== -1 || comments1.indexOf(redactString) !== -1) {
var updatedComments = comments1.replaceAll(redactString, '[REDACTED]');
commentsGR.newvalue = updatedComments;
if (commentsGR.fieldname != 'work_notes' && commentsGR.fieldname != 'comments') {
commentsGR.oldvalue = '';
}
commentsGR.autoSysFields('false');
commentsGR.update();
}
}

Aishwarya Shelake

It works for me.