- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2023 12:08 PM
I am trying to use a scheduled job to add an additional comment to RITM that meet a certain query. I want RITM that have the state open, approval requested, and created date more than 6 and less than 9 days from the query. Here is the code I came up with, but it isn't making any additional comments.
var gr = new GlideRecord('sc_req_item');
gr.addQuery('state', 'open');
gr.query();
while (gr.next()) {
var comment = 'New comment here?';
gr.work_notes = comment + '\n\n' + gr.work_notes.getJournalEntry(1);
gr.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2023 01:48 PM
Had a lot of issues with the scheduled job. One being testing was hard since it had to query soooo many records it actually slowed down the whole instance for a whole afternoon of testing. Ended up making it work with a flow. Trigger was when a request was made we did a wait for duration and then looked up the ritm table for those created relative to before 5 days ago and after 7 days ago then updated the record with the additional comment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2023 12:16 PM
Hi,
Please try below line and use setworkflow(false) in code:
gr['comments'].setJournalEntry("Some comment here.");
Please mark it as helpful (or) correct if it resolves your issue.
Thanks & Regards,
Sumanth Meda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2023 12:34 PM
Is this how you would adjust my first bit of code? It didn't work this way when I executed the SJ.
var gr = new GlideRecord('sc_req_item');
gr.addQuery('state', 'open');
gr.query();
while (gr.next())
var comment = 'Add comment here';
gr['comments'].setJournalEntry(comment + '\n\n' + gr['comments'].getJournalEntry(1));
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2023 12:58 PM
Hi,
Can you run this in the background script and check how many records are printing:
Add gs.info statements to log values in the while loop.
var gr = new GlideRecord('sc_req_item');
gr.addQuery('state', 'open');
gr.query();
gs.info(gr.getRowCount());
while (gr.next()){
gs.info(gr.numberfieldname);
var comment = 'Add comment here';
gr['comments'].setJournalEntry(comment + '\n\n' + gr['comments'].getJournalEntry(1));
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2023 12:51 PM - edited ‎05-10-2023 12:53 PM
Hi Erik,
Try logic like:
var gr = new GlideRecord('sc_req_item');
gr.addQuery('state', '1');
gr.query();
gs.info("Found " + gr.getRowCount() + " records to process.");
while (gr.next()) {
var newComment = 'New comment here?';
gr.work_notes.setJournalEntry(newComment + '\n\n' + gr.work_notes.getJournalEntry(1));
gs.info("Number: " + gr.number + " work_notes = " + gr.work_notes);
// gr.update();
}
Use the chioce value '1' that corresponds to "Open" for the state field.