
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2025 03:24 AM - edited 04-05-2025 03:26 AM
Need a client script to fetch date which is exactly one year from today in dd-MM-yyyy format
- In sam_sw_product_lifecycle, lookup for records with below conditions:
- Lifecycle Phase (lifecycle_phase) is End of Life
- Product (norm_product) is not empty
- Phase start date (start_date) is exactly 1 year from today
that phase start date output should be exactly one year from today in dd-MM-yyyy format
below is the record i should be able to fetch in the output
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2025 05:33 AM
As per your requirement it's server side code and seems to be scheduled job etc
You need to calculate 1 year in script, simply use this in server side
// Get today's date and format it to dd-MM-yyyy
var today = new GlideDateTime();
var oneYearFromToday = new GlideDateTime();
oneYearFromToday.addYears(1);
var formattedDate = oneYearFromToday.getLocalDate().toString().split('-').reverse().join('-');
// GlideRecord to query sam_sw_product_lifecycle table
var gr = new GlideRecord('sam_sw_product_lifecycle');
gr.addQuery('lifecycle_phase', 'End of Life');
gr.addNotNullQuery('norm_product');
gr.addQuery('start_date', oneYearFromToday);
gr.query();
// Process the results
while (gr.next()) {
gs.info('Record found with start_date exactly one year from today: ' + formattedDate);
}
Output: When I ran the script in background for sys_user and date field and it gave me correct output, 1 year from today is 6th April 2026
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2025 03:37 AM - edited 04-05-2025 08:47 AM
Hello @Gautam Raj ,
Please provide more details about the requirement.
It sounds like you want to query some records from a table that match the given criteria, including start_date being exactly one year from now.
But what shall then happen with those records? Are they to be updated, or something else? Asking because depending on the actual requirement a Client Script might not be the best idea.
Regards,
Robert

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2025 03:55 AM
below is the actual requirement .. but i need the code to get a record which is exactly one year from today
1. System to send a notification to Product Owners on product EOL / EOS with below conditions:
- In sam_sw_product_lifecycle, lookup for records with below conditions:
- Lifecycle Phase is End of Life
- Product is not empty
- Phase start date is exactly 1 year from today
- Stop if no record found
- In cmdb_software_product_model, lookup each record found above with below conditions:
- Product is <Product found in sam_sw_product_lifecycle>
- Version is <Version found in sam_sw_product_lifecycle>
- GTS ID is not empty
- Stop if no record found and proceed with next product (if any)
- In cmdb_sam_sw_discovery_model, lookup each record found above with below conditions:
- Software model is <Display name found in sam_sw_product_lifecycle>
- Stop if no record found and proceed with next product (if any)
- In cmdb_sam_sw_install, lookup each record found above with below conditions:
- Discovery model is <Display name found in cmdb_sam_sw_discovery_model>
- Stop if search result count is 0 and proceed with next product (if any)
- If search result count is more than 0, proceed with step 5
- In sn_apm_trm_standards_product_lifecycle, lookup each GTS ID that is left with below conditions:
- GTS ID is <GTS ID found in sn_apm_trm_standards_product_lifecycle>
- Strategic Investment Status is Evaluation or Invest or Contain
- Stop if no record found and proceed with next product (if any)
- In sn_apm_trm_standards_product, lookup product record found above with below conditions:
- Owner is not Blank
- Owner.Action is not Termination
- Category is one of:
- Technology & Architecture
- TA-End User Services
- Desktop Hardware
- Desktop Management
- Desktop Software
- Analytics
- Browser Extensions
- Client OS
- Core Desktop Applications
- Deployment Services
- Desktop Software-Miscellaneous
- Desktop Software-Miscellaneous Tools
- Desktop Software-Others
- Laptops
- Microsoft Office Products
- Miscellaneous
- Miscellaneous Software
- Monitors
- Others
- Web Browsers
- Workstations
- Stop if no record found and proceed with next product (if any)
- Only trigger notification for Software Product Lifecycle record which meets all the conditions above
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2025 04:12 AM - edited 04-07-2025 12:42 AM
Hello @Gautam Raj ,
Thanks for the clarification. So what you actually need is not a Client Script but a server side query to check if the notification is to be sent.
Your requirements do not specify what should trigger this process, e.g. whether it's a daily job or some Business Rule, but in any case here is the piece of code that will check if the first condition is met:
var gr = new GlideRecord('sam_custom_sw_product_lifecycle');
gr.addNotNullQuery('product_name');
gr.addQuery('lifecycle_phase', 'end_of_life');
gr.addQuery('start_date', gs.daysAgoStart(-365));
gr.query();
while (gr.next()) {
gs.info('found record with start date ' + gr.start_date.getByFormat("dd-MM-yyyy"));
// proceed with the other checks
}
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 12:44 AM
Hello @Gautam Raj ,
Did you check the script that I provided?
Given the following record in the table
it gives the following output:
found record with start date 07-04-2026
Regards,
Robert