Fix script to copy data from sys_journal to a new field on INC

Russell Abbott
Kilo Sage

I created a new field on my INC form. This field uses a BR to update with the current date when a new Customer Comment is added. To be reported on later (Show me Incidents without a Customer Comment in x number of days)

This is great going forward.

Would I be able to run a fix script to populate this field (u_last_customer_update) with the date of the most recent customer comment?

I have the below, but what comes after the = I'm not sure

var incGR=new GlideRecord('incident');
incGR.addEncodedQuery('active=true^u_last_customer_updateISEMPTY');
incGR.query();
while(incGR.next()){
	incGR.u_last_customer_update=incGR.comments.created;
	incGR.update();
}

 

1 ACCEPTED SOLUTION

var incGR=new GlideRecord('incident');
incGR.addEncodedQuery('active=true^u_last_customer_updateISEMPTY');
incGR.query();
while(incGR.next()){
    var journalEntries = new GlideRecord("sys_journal_field");
    journalEntries.addQuery("name", "incident");
    journalEntries.addQuery("element_id", incGR.getValue("sys_id"));
    journalEntries.addQuery("element", "comments");
    journalEntries.orderByDesc("sys_created_on");
    journalEntries.setLimit(1);
    journalEntries.query();
    if(journalEntries.next()){
        incGR.setValue("u_last_customer_update", journalEntries.getValue("sys_created_on"));
        incGR.setWorkflow(false); // Not executing BR's
        incGR.autoSysFields(false); // Not updating system fields such as updated by, updated
	    incGR.update();
    }	
}

 

Please check this if it helps.

View solution in original post

5 REPLIES 5

very very helpful