Flow Designer - 30 days before expiration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
What action I will add in my flow that will notify the manager 30 days before the expiration date? and Update Status as Expired if the Current Date > Expiration Date.
- Labels:
-
Custom Tables
-
Flow Designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
Hello @GwynethPhoS ,
Please check this accepted solution, this should work for you
https://www.servicenow.com/community/itsm-forum/sent-notification-30-and-14-days-before-the-expiry-d...
If my response helped mark as helpful and accept the solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
Hi @GwynethPhoS,
You can use the Notification/Email action for getting notifications. Also, you will need to use a Scheduled Job script, which will help you get notified 30 days before expiration.
You can refer this script for Scheduled Job:
(function() {
var today = new GlideDateTime();
// Get date after 30 days
var notifyDate = new GlideDateTime();
notifyDate.addDaysUTC(30);
var gr = new GlideRecord('YOUR_TABLE_NAME'); // replace with your table
gr.addActiveQuery(); // optional if records are active
// Query records where expiration date is today + 30 days
var qc = gr.addQuery('expiration_date', '>=', today);
qc.addCondition('expiration_date', '<=', notifyDate);
gr.query();
while (gr.next()) {
// Send notification to manager
if (gr.manager) { // replace with correct manager field
gs.eventQueue(
'record.expiration.reminder', // create this event
gr,
gr.manager,
gr.getDisplayValue('expiration_date')
);
}
}
// ---------------------------------------
// Update status when expired
// ---------------------------------------
var expired = new GlideRecord('YOUR_TABLE_NAME');
expired.addQuery('expiration_date', '<', today);
expired.addQuery('status', '!=', 'Expired'); // avoid repeated updates
expired.query();
while (expired.next()) {
expired.status = 'Expired'; // adjust field value if it's a choice
expired.update();
}
})();
If you find my answer useful, please mark it as Helpful and Correct 😊
Regards,
Soham Tipnis
ServiceNow Developer || Technical Consultant
LinkedIn: www.linkedin.com/in/sohamtipnis10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
Hello @GwynethPhoS ,
I also tried the similar use case although according to your requirement :
-> Make one action taking input as 'expiration date'
-> write script into that will count 30 days before expiration and give output whether to notify the manager or not
(function execute(inputs, outputs) {
var now = new GlideDateTime();
var expiration = new GlideDateTime(inputs.expiration_date);
// Calculate 30 days before expiration (calendar days)
var notifyDate = new GlideDateTime(expiration);
notifyDate.addDaysUTC(-30);
// Notify manager 30 days before
if (
now.getDate().getValue() == notifyDate.getDate().getValue()
) {
outputs.notify_manager = 'true';
} else {
outputs.notify_manager = 'false';
}
})(inputs, outputs);
If this return the output as true then Notify the manager.
*Also Below according to your requirement after [Current Date > Expiration Date] -> Update Status as Expired..
If my response helped mark as helpful and accept the solution.
