Duration time for Requests
						
					
					
				
			
		
	
			
	
	
	
	
	
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
01-24-2017 10:10 AM
Currently, OOB is not setup to populate the Duration fields in RITM's. Anyone know how to set this up?
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
04-13-2018 09:46 AM
You can do Scheduled Script that run daily
calendar_duration
var gr = new GlideRecord("task");
gr.addEncodedQuery('active=false^calendar_durationISEMPTY^sys_class_name=sc_request');
gr.autoSysFields(false); // so that the records don't have system updates
gr.query();
while(gr.next()) {
	var gdt1 = new GlideDateTime(gr.sys_created_on.getDisplayValue());
	var gdt2 = new GlideDateTime(gr.closed_at.getDisplayValue());
	var dur = gs.calDateDiff(gdt1, gdt2, false);
	gr.calendar_duration = dur;
	gr.setWorkflow(false); 
	gr.update();
}
Business duration
var gr = new GlideRecord("task");
gr.addEncodedQuery('active=false^business_durationISEMPTY^sys_class_name=sc_request');
gr.autoSysFields(false); // so that the records don't have system updates
gr.query();
while(gr.next()) {
	// Create schedule 
var gsBusiness =new GlideSchedule('xxxxxxxxxxxxxxxxxxxxx'); //xxxxx sys id of schedule
// Get duration based on schedule
gr.business_duration = gsBusiness.duration(gr.sys_created_on.getGlideObject(), gr.closed_at.getGlideObject());
	gr.setWorkflow(false); 
	gr.update();
}
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
04-13-2018 10:14 AM
How can I be confident that it'll set it from there when it won't set it from a business rule?
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
04-13-2018 10:50 AM
My script is different and works on my instance. I'm doing below (getGlideObject) instead of getDisplayValue
gr.business_duration = gsBusiness.duration(gr.sys_created_on.getGlideObject(), gr.closed_at.getGlideObject());
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
04-13-2018 11:29 AM
So, I did some more work on it and in my log, I have it showing that the value gets set, but when i look at the list of tasks that are closed the duration field is empty. Maybe something is clearing the value of that field. This is mysterious.
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
07-22-2019 10:59 AM
I tried running this script as a "Fix Script" since I only need it to run once (updates the Duration field of Tasks where State = closed complete)
Unfortunley, I'm not getting any results in the Duration field.
var gr = new GlideRecord("task");
gr.addEncodedQuery('active=false^calendar_durationISEMPTY^sys_class_name=sc_request');
gr.autoSysFields(false); // so that the records don't have system updates
gr.query();
while(gr.next()) {
 var gdt1 = new GlideDateTime(gr.sys_created_on.getDisplayValue());
 var gdt2 = new GlideDateTime(gr.closed_at.getDisplayValue());
 var dur = gs.calDateDiff(gdt1, gdt2, false);
 gr.calendar_duration = dur;
 gr.setWorkflow(false); 
 gr.update();
}
