Sending notification if there is no update

chandan86patra
Tera Contributor

Hi All, 

 

How to write the script if there is no update from last days after that notifications should trigger. 

 

Can you guide me the script. 

3 REPLIES 3

Amarjeet Pal
Kilo Sage
Kilo Sage

Hello @chandan86patra ,

// Set the number of days without an update required to trigger the notification
var daysWithoutUpdate = 1;

// Create a new GlideRecord object for the specified table name
var record = new GlideRecord('tablename');

// Add any desired filters to limit which records get checked
record.addQuery('field', 'value'); // Replace 'field' and 'value' with your desired conditions

// Execute the query to retrieve matching records
record.query();

while (record.next()) {
   // Get the last updated date/time from the current record being checked
   var lastUpdated = new GlideDateTime(record.sys_updated_on);
   lastUpdated.setTZ('UTC');

   // Get the current date and time in UTC format
   var now = new GlideDateTime();
   now.setTZ('UTC');

   // Calculate the difference between the current date/time and last updated date/time in days
   var diffInDays = gs.dateDiff(now, lastUpdated, true);

   if (diffInDays >= daysWithoutUpdate) {
      // Trigger your notification here for this specific record
    
   gs.eventQueue("my.notification.event", current.object, ' Parm1' ,'Parm2 ');
}

 

Thanks

Amarjeet Pal

Hi @Amarjeet Pal ,

 

This looks like a chatGPT answer, and isn't very accurate, nor does it answer the question.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Peter Bodelier
Giga Sage

Hi @chandan86patra 

 

You could use a daily scheduled script, to query records which are not updated for x days, and then insert an event to trigger a notification.

 

Since your question doesn't give a lot of detail, you could start from something like this:

 

var record= new GlideRecord('tablename');
record.addEncodedQuery("sys_updated_onRELATIVELT@dayofweek@ago@1");
record.query();
while (record.next()) {
  gs.eventQueue('eventname', record, '', '', '')
}

Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.