
- 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-06-2025 08:54 PM
Hello @Gautam Raj
Please confirm if you checked my answer. Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for my efforts and also it can move from unsolved bucket to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeE