Get last journal entry in scheduled job

Richard Thomas2
Tera Contributor

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?

find_real_file.png

 

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

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

suvro
Mega Sage
Mega Sage

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

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Musab Rasheed
Tera Sage
Tera Sage

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

Please hit like and mark my response as correct if that helps
Regards,
Musab