How to send a email based change record state updated

Pavan Kumar28
Tera Contributor

Hi all,

I am trying to send an email to the change requester, but I am missing some logic. My requirement is to trigger the email automatically on a weekly basis. For example, if the change is approved on December 20th (Friday), the email should be sent to the requester on December 27th (next Friday). The email should calculate 7 days from the state change (eg: from "Scheduled for Approval" to "In Progress") and not from other field updates (eg: work notes, additional comments, etc.).
My current code is sending emails for other field updates as well. Can someone please help me correct this?

My code:

var grChange = new GlideRecord('change_request');
   //grChange.addEncodedQuery('state=-4^sys_updated_on>=javascript:gs.beginningOfToday()');
grChange.addEncodedQuery('state=-4^sys_updated_onRELATIVEGT@dayofweek@ago@7');

    grChange.query();
    while (grChange.next()) {
        gs.log('Change moved from "Scheduled for Approval" to "In Progress": ' + grChange.number);
       
        gs.eventQueue('Weekly.CR.CTask.Update', grChange);
    }

Regards,
Pavan.
6 REPLIES 6

@Pavan Kumar28 

Hope you are doing good.

Did my reply answer your question?

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

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

Runjay Patel
Giga Sage

Hi @Pavan Kumar28 ,

 

Flow designer is the right fit for this requirement, As suggested by @Ankur Bawiskar follow the step, That is the only way you can achieve it.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------