Scheduled job email reminder 30/60/90

Richard Thomas2
Tera Contributor

Hi Experts,

I need to send a email reminder and create comments on a record if the user hasnt updated it after 30 days and 60 days.

How can create a comment on the record with out updating the record - I've tried gr.autoSysFields(false); but this fires the notification and does not update the record (see code below)

var gr = new GlideRecord('sn_hr_core_case');
gr.addEncodedQuery('sys_updated_onRELATIVELT@dayofweek@ago@30');
gr.addQuery('assignment_group' ,'IN',gs.getProperty('sn_hr_core.hr.assignmemt.group'));
gr.query();

while (gr.next()) {
    gr.comments = '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. 
    gr.autoSysFields(false);
    gr.update();

Can anyone advise?

Thanks

Richard

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

why don't you just update the comments?

why this is required ->     gr.autoSysFields(false);

Regards
Ankur

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

OlaN
Giga Sage
Giga Sage

Hi,

Journal fields (like additional comments and work notes) are special, they exist as a separate record.
So it's not possible to write a comment or a work note without updating the record (sn_hr_core_case).

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

alternative here -> create record into sys_journal_field using GlideRecord while iterating

var gr = new GlideRecord('sn_hr_core_case');
gr.addEncodedQuery('sys_updated_onRELATIVELT@dayofweek@ago@30');
gr.addQuery('assignment_group' ,'IN',gs.getProperty('sn_hr_core.hr.assignmemt.group'));
gr.query();
while (gr.next()) {
	var rec = new GlideRecord('sys_journal_field');
	rec.initialize();
	rec.name = 'sn_hr_core_case';
	rec.element_id = gr.getUniqueValue();
	rec.element = 'comments';
	rec.value = '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';
	rec.insert();
}

Regards
Ankur

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

@Richard Thomas 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

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