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

Prasad Pagar
Mega Sage

Hi @Pavi 

There is no OOB field I believe which store on hold time apart from SLA Definition. SLA Definition too if you are pausing SLA in On hold state then you will get the time in Pause time. If it dosent help then there is no way other than creating custom field and then storing datetime when incident move to On hold state.

Then you can use if in API

Hope this helps

Thank you
Prasad

Thanks for your reply. I will check whether it is available in SLA definition.

But can you also elaborate on creating a custom field and storing datetime when incident state changes to On hold. How it can be done?

Hi @Pavi 

Yes you can create Simple Date Time field and store current date time in it using BR.

Basically when your incident will move to on hold state your BR should get trigger and store current timestamp in your custom field.

See the BR mentioned by Ankur. It should work to autopopulate current date time

Thank you
Prasad 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

As mentioned incident table doesn't have any OOB field for holding that.

But you can use API on this sys_history_line table which holds data when state changed to On Hold

But using that Table will have performance impact

Query as this -> set.tableSTARTSWITHincident^set=b52c5b6e076c74102011ff208c1ed075

find_real_file.png

Regards
Ankur

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