Using a scheduled job to add an additional comment to a RITM

Erik Stuer
Tera Guru

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();
}

1 ACCEPTED SOLUTION

Erik Stuer
Tera Guru

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. 

View solution in original post

10 REPLIES 10

Sumanth16
Kilo Patron

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

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();
}

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();
}

 

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.