Populating a Duration Field

I recently had a use-case where I needed to populate a custom date/time field with time that had passed since a group of agile stories had been created.

Here is how I did that:

var currentTimeStamp = new GlideDateTime(); //Create current timestamp
currentTimeStamp = currentTimeStamp.getDisplayValue(); //Set it to a string so dateDiff can us it

var gr = new GlideRecord(‘rm_story’); //Get active, unassigned stories
gr.addQuery(‘active’, true);
gr.addQuery(‘sprint’, ”);
gr.addQuery(‘assigned_to’, ”);
gr.query();

while(gr.next()) { //Loop through the stories
     var startTimeStamp = gr.getDisplayValue(‘sys_created_on’);
     var dur = gs.dateDiff(startTimeStamp, currentTimeStamp, false);
     var durObject = new GlideDuration(dur);
     gr.u_time_since_creation = durObject; //Set value in custom field
     gr.update();
}

 

 

Leave a Reply