How to add comments to a record via background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2015 11:23 AM
Hello All,
I created a background script to cleanup some records and I want to add a comment to each record that is cleaned up. I know this must be a syntax thingy - I'm fairly new to scripting. The comment appears in the Activity log, however, it does not appear as a new entry. It places the comment inside the previous comment in the log:
Here is my code:
processCleanupTickets();
function processCleanupTickets() {
var gr = new GlideRecord('sc_req_item');
gr.orderBy('sys_created_on');
gr.setLimit(1);
gr.addQuery('opened_at', '<', '2015-06-01');
gr.query();
while (gr.next()) {
gr.setValue('u_requester',gr.variables.Requestor);
gr.setValue('u_deliver_to',gr.variables.requested_for);
gr.comments = 'Requested For and Deliver To fields populated from variables so VIP and Legal Hold icons will show on the fields.';
gr.setWorkflow(false);
gr.update();
gs.print('RITM ' + gr.number + ' Opened ' + gr.opened_at + ' Requested For ' + gr.u_requester);
}
}
Any help is greatly appreciated!
Thanks,
Laurie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2015 11:31 AM
Hello Laurie,
As comments field is of type journal input it will not show that in the field once updated. You can see it in Activity log. If it is a journal type then the comments will be shown below the field.
Using Journal Fields - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2015 12:51 PM
Thank you, Saritha. I knew it would be visible in the Activity log. It was just inserting the comment into a previous log note.
I figured out I needed to remove the gr.setWorkflow(false) and it would create a new log entry with the correct date/time stamp.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2015 01:11 PM
Yes. setWorkflow(false) disables running of any business rules.