How to get Incident state change timestamp

Pavi1
Kilo Contributor

Hi Team

I have one of the incident status as "On Hold" in ServiceNow. I have an API script in Python which fetches all the incident from ServiceNow. How do I get the timestamp of when incident state is changed to "On Hold" like we have resolved_at.

Basically, I need a variable that holds On Hold timestamp for my script logic. Which table holds this value? to which table do I have to pass the incident sys_id and get that On Hold timestamp?

Please let me know ASAP if anyone knows how to get this done.

1 ACCEPTED SOLUTION

@Pavi 

You can use before update BR on incident table to set that custom date/time field

BR: Before Update

Condition:

find_real_file.png

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	current.u_field = new GlideDateTime(); // set the now time in this

})(current, previous);

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

8 REPLIES 8

@Pavi 

You can use before update BR on incident table to set that custom date/time field

BR: Before Update

Condition:

find_real_file.png

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	current.u_field = new GlideDateTime(); // set the now time in this

})(current, previous);

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks Ankur. Let me Try. Where does this value gets stored? is that u_field custom field where the value gets stored for each incidents? is it in incident table? 

Yes u_field is the name of the field which you create of type Date/Time

It will be stored only when incident state changes to On Hold for the 1st time

Again if incident moves to In Progress and if you don't want to set this field again when incident moves to On Hold then add this in BR condition

State [Changes to] On Hold

AND

Field [IS EMPTY]

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi,

You could also use the API for the OOB table as an alternative for creating custom field on your table.

Note: create custom field has cost implication as per your ServiceNow Subscription

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader