Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Updating date field in previously resolved tickets

MegC
Tera Contributor

Hello all, 

 

I am attempting to update a date field when a ticket was changed to resolved state. I was trying to use a glide walker, but I don't see that plugin in our list of installed (unless I'm not looking in the right place). I have checked to make sure that audit is selected on the form in question. I have updated the form so that when the state is marked as resolved it will update the resolved date field correctly, but now I'm trying to updated previously resolved tickets. 

 

The fix script I tried: 

var gr = new GlideRecord('u_content_requests');

gr.addQuery('state', '5');
gr.addNullQuery('u_resolved_date');
gr.query();

var count = 0;

while (gr.next()) {

	var hw = new sn_hw.GlideHistoryWalker(gr.getTableName(), gr.getUniqueValue());
	
	if (hw.walkToFieldValue('state', 'resolved')) {

		var historySnapshot = hw.getUpdateSnapshot();
		var actualDate = historySnapshot.sys_updated_on;
		
		gr.u_resolved_date = actualDate;

	gr.setWorkflow(false);
	gr.autoSysFields(false);
	gr.setLimit(10);
	gr.update();
	
	gs.info("Success: Updated  " + gr.number + "with date: " + actualDate);
	count++;
	}
	
	else {
		gs.warn('no history found for content request: ' + gr.number);
	}
	gs.info('fix script for content requests completed. total updated: ' + count);
}

 

Any insight or assistance would be appreciated! 

5 REPLIES 5

Tanushree Maiti
Giga Sage

Hi MegC,

 

If Your table/application is having any backend flow/workflow, it is best using that you can store the previous value of your Date field in scratchpad and use that till end of the flow.

 

You can do it using by hitting audit table if your custom table is audited. BUT it is not at all recommended. it can cause performance issue of your instance in long run.

 

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: