How to capture it for existing Problem Tickets which are already in Root Cause Analysis state?

Piyush Dwivedi
Tera Contributor

I am able to populate time taken by problem ticket from state change from new to Root Cause Analysis,

How to capture it for existing Problem Tickets which are already in Root Cause Analysis state?

2 REPLIES 2

Rafael Batistot
Tera Sage

Hi @Piyush Dwivedi 

 

For existing Problem records already in Root Cause Analysis state, just run a one-time background script to calculate and populate the time field.

 

var gr = new GlideRecord('problem');
gr.addQuery('state', '101'); // Replace 101 with your RCA state value
gr.addNullQuery('u_time_to_rca'); // Only if your field is empty
gr.query();
while (gr.next()) {
// Assuming 'sys_updated_on' is when it entered RCA, adjust if you track it differently
var created = new GlideDateTime(gr.sys_created_on);
var rca = new GlideDateTime(gr.sys_updated_on);
var diffMillis = GlideDateTime.subtract(rca, created);
gr.u_time_to_rca = diffMillis.getNumericValue(); // Or format as needed
gr.update();
}

That way you:

  • Keep your business rule/flow for new tickets as-is.
  • Use this script only once to backfill historical data.

 

 

@Rafael Batistot Thanks for the response, I tried to run in Background Script but its not working.