
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2022 02:34 AM
I'm trying to check the last journal entry of a record for specific text. If that text exists then I want to update the record. Script is here - my question is it possible to query the last journal entry in a scheduled job?
var gr = new GlideRecord('sn_hr_core_case');
var notes = gr.work_notes.getJournalEntry(1);
gr.addEncodedQuery('active=true^sys_updated_onRELATIVELT@dayofweek@ago@60');
gr.addQuery('assignment_group', 'IN', gs.getProperty('xxxxxxxxxxxxxxxxxxxxxxx'));
gr.query();
while (gr.next()) {
if (gr.notes === 'You have not provided an update on your case within the last 30 days. It is really important that you provide an update within the next 60 days or the case will be closed. Click on the Ask Archie link below and type in your HRC number ${number} to update on the progress made or outcome reached' )
gr.comments = 'You have not provided an update on your case within the last 60 days. It is really important that you provide an update within the next 30 days or the case will be closed. Click on the Ask Archie link below and type in your HRC number ${number} to update on the progress made or outcome reached';
gr.autoSysFields(false);
gr.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2022 02:46 AM
Hi,
update as this
var gr = new GlideRecord('sn_hr_core_case');
gr.addEncodedQuery('active=true^sys_updated_onRELATIVELT@dayofweek@ago@60');
gr.addQuery('assignment_group', 'IN', gs.getProperty('xxxxxxxxxxxxxxxxxxxxxxx'));
gr.query();
while (gr.next()) {
var notes = gr.work_notes.getJournalEntry(1);
if (notes.indexOf('You have not provided an update on your case within the last 30 days. It is really important that you provide an update within the next 60 days or the case will be closed. Click on the Ask Archie link below and type in your HRC number ' + gr.number + ' to update on the progress made or outcome reached') > -1)
gr.comments = 'You have not provided an update on your case within the last 60 days. It is really important that you provide an update within the next 30 days or the case will be closed. Click on the Ask Archie link below and type in your HRC number ' + gr.number + ' to update on the progress made or outcome reached';
gr.autoSysFields(false);
gr.update();
}
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2022 02:46 AM
try below
var gr = new GlideRecord('sn_hr_core_case');
gr.addEncodedQuery('active=true^sys_updated_onRELATIVELT@dayofweek@ago@60');
gr.addQuery('assignment_group', 'IN', gs.getProperty('xxxxxxxxxxxxxxxxxxxxxxx'));
gr.query();
while (gr.next()) {
var notes = gr.work_notes.getJournalEntry(1);
if (notes == 'You have not provided an update on your case within the last 30 days. It is really important that you provide an update within the next 60 days or the case will be closed. Click on the Ask Archie link below and type in your HRC number '+gr.number+' to update on the progress made or outcome reached' )
gr.comments = 'You have not provided an update on your case within the last 60 days. It is really important that you provide an update within the next 30 days or the case will be closed. Click on the Ask Archie link below and type in your HRC number'+ gr.number+' to update on the progress made or outcome reached';
gr.autoSysFields(false);
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2022 02:46 AM
Hi,
update as this
var gr = new GlideRecord('sn_hr_core_case');
gr.addEncodedQuery('active=true^sys_updated_onRELATIVELT@dayofweek@ago@60');
gr.addQuery('assignment_group', 'IN', gs.getProperty('xxxxxxxxxxxxxxxxxxxxxxx'));
gr.query();
while (gr.next()) {
var notes = gr.work_notes.getJournalEntry(1);
if (notes.indexOf('You have not provided an update on your case within the last 30 days. It is really important that you provide an update within the next 60 days or the case will be closed. Click on the Ask Archie link below and type in your HRC number ' + gr.number + ' to update on the progress made or outcome reached') > -1)
gr.comments = 'You have not provided an update on your case within the last 60 days. It is really important that you provide an update within the next 30 days or the case will be closed. Click on the Ask Archie link below and type in your HRC number ' + gr.number + ' to update on the progress made or outcome reached';
gr.autoSysFields(false);
gr.update();
}
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2022 02:47 AM
Hello,
You can use
current.comment.getJournalEntry(1) to get latest entry however you won't get desire result as comments/work notes will be appended with extra text like name and date so you have to use indexof() function in order to check this. Please try.
Please hit like and mark my response as correct if that helps
Regards
Regards,
Musab