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

Chetan Mahajan
Kilo Sage
Kilo Sage

Hello @AishwaryaS1 ,

                                     You can delete comments on any form by below links

* Journal Entry : https://instance-name.service-now.com/sys_journal_field_list.do?sysparm_query=element_id=sys_id of record

* Audit Entry : https://instance-name.service-now.com/sys_audit_list.do?sysparm_query=documentkey=sys_id of record

* History Set : https://instance-name.service-now.com/sys_history_set_list.do?sysparm_query=id=sys_id of record

* Email Entry : https://instance-name.service-now.com/sys_email_list.dosysparm_query=instance=sys_id of record

You can delete entries from here, also you can try to call it in UI action for delete it on button.

 

Kindly mark correct and helpful if applicable

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

Aishwarya Shelake

MattSN
Mega Sage
Mega Sage

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

Aishwarya Shelake