How to get the previous value of the state filed using client script OR UI Action button

utkarsh2908
Kilo Explorer

I have a requirement where user have feature to reopen the incident ticket, at the time of reopening the ticket state of the current incident will be redirected to its previous state instead of work in progress.

case 1: if the incident is moved form on hold to resolved and then user clicks on reopen button so ticket should be redirected to the on hold state.

case 2: if the incident is moved form work in progress to resolved and then user clicks on reopen button then ticket should be redirected to the work in progress state.

 

any how want to redirect my ticket to its previous state. 

3 REPLIES 3

Allen Andreas
Administrator
Administrator

Hi,

I can get what you're trying to do here, but I'd like to advise that I don't think this is a good idea.

Why would you want it to go from On Hold to resolved....then BACK to On hold upon user reopening it? I'm almost betting it was On Hold most likely waiting on the user to supply some information or something? So...why would it go back there when the user reopened it?

Technically, I would think (and how I do it) it goes back to In progress...because that is the way technicians knows what's waiting for them. If they see on hold...they may not even know that the user opened it back up....so it sits until they go: wait...that updated date/time is pretty recent....let me click and see what they said...

You may want to review this requirement again and present how this could negatively impact the business.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

p_espinar
Kilo Guru

 

Yes, I also think that it is not a good idea (I always turn to Work in Progrees from Reopen) but if you insist I think it is easy to create one custom field, lets say prev_status, where you store the previous state in every state change. Then in your reopen action you set it from that field.

Un saludo,
Pablo Espinar
Consultant at Econocom Spain

Please mark this response correct if I've answered your question. Thanks!

Aaron Munoz
Tera Guru

I agree with the previous posters that this particular use case would be a bad practice. That being said, you can have a function like the following in a script include. Just make sure that auditing is turned on for the field you want. Parameter "record" is the sys_id of your record and "field" is the column name of your field.

function getPreviousValue(record, field){
	var audit = new GlideRecord('sys_audit');
	audit.orderByDesc('sys_created_on');
	audit.addQuery('documentkey', record);
	audit.addQuery('fieldname', field);
	audit.query();
	if(audit.next()){
		return audit.getValue('oldvalue');
	}
}

Please mark as correct or helpful as appropiate