Hi All
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2023 09:25 PM
Hi All,
I Have two Date Fields
1. start date 2. end date
I have another Field count Days
How to Decrease Days as per system date.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2023 09:41 PM
Hi @basha shaik ,
Assuming all these fields shown in your image are from custom table n as they are Read only. U can write a schedule job which runs daily calculating the days left by subtracting start n end date n updating the count date field for all records on daily basis.
Please mark my answer helpful & accepted if it helps you resolve your query.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2023 10:21 PM
can you Please provide code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2023 10:36 PM
Hi @basha shaik ,
U can refer below code, please make necessary changes wherever required in terms of field names.
var gr = new GlideRecord('change_request');// please use proper table name in which ur field are present
gr.addEncodedQuery('start_dateISNOTEMPTY^end_dateISNOTEMPTY');//script should only execute for records where both fields are filled
gr.query();
while (gr.next()) {
var startDate = new GlideDateTime(gr.start_date);//use proper backend name of the start date field
var endDate = new GlideDateTime(gr.end_date);//use proper backend name of the end date field
var duration = GlideDateTime.subtract(endDate, startDate);
var days = duration.getDayPart();// this will give u the number of days left
gr.count_date = days;
gr.update();
}
Please mark my answer helpful & accepted if it helps you resolve your query.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2023 11:00 PM
Hi @basha shaik ,
If the solution did work for you can make it accepted as well & close the thread so for others to benefit from it please.
Thanks,
Danish