Hi All
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 01:13 AM
I Have Two Date Fields
1.statrt date
2. End Date
3rd Field Count Date
I Have Create BR on Count date.
BR Working fine
I have write below script scheduled job
var gr = new GlideRecord('ast_contract');
gr.addEncodedQuery('startsISNOTEMPTY^endsISNOTEMPTY');
gr.orderByDesc('sys_updated_on');
//gr.setLimit(1);
gr.query();
while (gr.next()){
var gdt = new GlideDateTime();
gr.u_count_date = GlideDateTime.subtract(gdt, gr.getElement("ends").getGlideObject()).getRoundDayPart();
gr.update();
}
how to Decreasing count day wise
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 02:56 AM
Use the logic used for business rule (if that is working) in the scheduled job and you won't need the business rule anymore.
Or simply, decrement the count in current schedule job.
Instead of
gr.u_count_date = GlideDateTime.subtract(gdt, gr.getElement("ends").getGlideObject()).getRoundDayPart();
Try
gr.u_count_date--;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 02:57 AM
@basha shaik Instead of calculating the Count date using a business rule, you can make Count Date a calculated field, a calculated field calculates the value each time a row is read on the list view. Hence you wouldn't have to be worried about decreasing the count date manually as the value would be calculated on the run time.
Here is the script for the calculated field.
(function calculatedFieldValue(current) {
// Add your code here
var gdt = new GlideDateTime();
var countDays = GlideDateTime.subtract(gdt, current.getElement("ends").getGlideObject()).getRoundDayPart();
return countDays; // return the calculated value
})(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 03:53 AM
please provided scheduled job script