- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 05:11 AM
Hi all,
I have a problem on Date field calculation, could any one give me suggestions?
1. I have Contract End Date in the Tabble
2. Create Scheduled Jobs with Script
Thank you
Best Regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 05:17 AM
so basically you want difference between contract end date and today's date in days?
if yes then use this
var gr = new GlideRecord('sn_hr_core_contract_management');
gr.addEncodedQuery('u_contract_end_dateISNOTEMPTY');
gr.query();
while (gr.next()) {
var contract_end_date = new GlideDateTime(gr.u_contract_end_date);
var today = new GlideDateTime();
var dur = new GlideDuration();
dur = GlideDateTime.subtract(today, contract_end_date);
var days = dur.getDayPart();
gs.info("HRIS Test" + days);
}
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
12-14-2023 05:17 AM
so basically you want difference between contract end date and today's date in days?
if yes then use this
var gr = new GlideRecord('sn_hr_core_contract_management');
gr.addEncodedQuery('u_contract_end_dateISNOTEMPTY');
gr.query();
while (gr.next()) {
var contract_end_date = new GlideDateTime(gr.u_contract_end_date);
var today = new GlideDateTime();
var dur = new GlideDuration();
dur = GlideDateTime.subtract(today, contract_end_date);
var days = dur.getDayPart();
gs.info("HRIS Test" + days);
}
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
12-14-2023 05:23 AM
Working now, thanks so much.