- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 10:22 PM
Hi,
Please provide the relevant code so that schedule job can be run daily if renewal date is expired.
Do let me know in case of any query.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 11:47 PM
Hello @Naman Jain2412
Please try code below
function checkExpiredPolicies() {
var gr = new GlideRecord('sn_compliance_policy'); // Target table: Compliance Policy
var today = new GlideDateTime(); // Get current date and time
var todayFormatted = today.getLocalDate().getValue();
// Query for policies where the 'u_next_renewal_date' is before today
// and the policy state is NOT already 'Expired' or 'Inactive' (adjust as per your state values)
gr.addQuery('u_next_renewal_date', '<', todayFormatted);
// We only want to process policies that are currently 'Active' (or similar state) and not already marked 'Expired' or 'Inactive'.
gr.addActiveQuery(); // Only process active records, if 'active' field exists and is used
gr.addQuery('state', '!=', 7); // Assuming 7 is your 'Expired' or 'Requires Review' state value
gr.addQuery('state', '!=', 3); // Assuming 3 is your 'Retired' state value (don't process retired policies)
gr.query();
var updatedCount = 0;
while (gr.next()) {
// 1. Update the state field
// IMPORTANT: Replace '7' with the correct integer value for your desired 'Expired' or 'Requires Review' state.
gr.state = 7; // Example: Set state to 'Expired' or 'Requires Review'
gr.update();
updatedCount++;
gs.eventQueue('policy.expired', gr, gr.owner.sys_id, gr.assignment_group.sys_id); // Pass relevant user/group sys_ids
}
checkExpiredPolicies();
Try this and let me know in case of queries
Thank you!
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 10:27 PM
Hi @Naman Jain2412
Try flow designer with Schedule type trigger. Let us know if you stuck ..
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 10:33 PM
Hello @Naman Jain2412
Please elaborate on your question.
What is the table name? What is the field name? Are there any choices in that field? so that we can make the logic of expiration
Thank you!
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 11:29 PM
Hi Thanks for the response Rushi
Table Name is sn_compliance_policy and field name is Next Renewal Date (u_next_renewal_date)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 11:47 PM
Hello @Naman Jain2412
Please try code below
function checkExpiredPolicies() {
var gr = new GlideRecord('sn_compliance_policy'); // Target table: Compliance Policy
var today = new GlideDateTime(); // Get current date and time
var todayFormatted = today.getLocalDate().getValue();
// Query for policies where the 'u_next_renewal_date' is before today
// and the policy state is NOT already 'Expired' or 'Inactive' (adjust as per your state values)
gr.addQuery('u_next_renewal_date', '<', todayFormatted);
// We only want to process policies that are currently 'Active' (or similar state) and not already marked 'Expired' or 'Inactive'.
gr.addActiveQuery(); // Only process active records, if 'active' field exists and is used
gr.addQuery('state', '!=', 7); // Assuming 7 is your 'Expired' or 'Requires Review' state value
gr.addQuery('state', '!=', 3); // Assuming 3 is your 'Retired' state value (don't process retired policies)
gr.query();
var updatedCount = 0;
while (gr.next()) {
// 1. Update the state field
// IMPORTANT: Replace '7' with the correct integer value for your desired 'Expired' or 'Requires Review' state.
gr.state = 7; // Example: Set state to 'Expired' or 'Requires Review'
gr.update();
updatedCount++;
gs.eventQueue('policy.expired', gr, gr.owner.sys_id, gr.assignment_group.sys_id); // Pass relevant user/group sys_ids
}
checkExpiredPolicies();
Try this and let me know in case of queries
Thank you!
Thank You!