Hi All

basha shaik
Tera Contributor

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();
}

 

bashashaik_1-1696838711480.png

how to Decreasing count day wise 

 

7 REPLIES 7

Omkar G1
Tera Expert

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--;

Sandeep Rajput
Tera Patron
Tera Patron

@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.

 

Screenshot 2023-10-09 at 3.26.10 PM.png

 

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);

please provided scheduled job script