I need to get the list of incidents(old incidents ) that were closed due to Auto closure functionality?

Reddy4811
Tera Expert

Dear all,

Scenario-1:-If the incident is in the state "solution proposed" and there is no action from the caller then it will be closed automatically after 5-days. (using BR)

Scenario-2:-if the incident is in the state "On Hold" and On Hold, the reason is "Awaiting User info". so in this case, if the caller is not responded to the incident up to 10days this incident will automatically be closed. (using Workflow)

My requirement is, I need to get all the list of those incidents which were closed based on the above scenarios, then I make the custom check box "true" on these incidents.

Could anyone please suggest to me the logic or some approach to do this....!

Please help

1 ACCEPTED SOLUTION

Hi,

data for comments and work_notes is stored in sys_journal_field

You can check for your incident record if there is any record in sys_journal_field with that comments or work notes value

if yes then it means it was closed by that scenario and then update the checkbox

Something like this

Ensure you give correct work_notes and comments text to find those records

var gr = new GlideRecord("incident");
gr.get("incidentSysId");

var rec = new GlideRecord('sys_journal_field');
rec.addEncodedQuery("name=incident^element=work_notes^valueLIKEclosed by scenario 1^ORvalueLIKEclosed by scenario 2");
rec.addQuery("element_id", gr.getUniqueValue());
rec.query();
if(rec.next()){
	
	// update your checkbox
	gr.u_checkbox = true;
	gr.update();
	
}

Regards
Ankur

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

View solution in original post

7 REPLIES 7

Hi @Ankur Bawiskar,

Thanks for your reply,

Yes, we are updating comments & work_notes on both scenarios.

I created one custom field(checkbox) on the incident and I just need to update only that checkbox if the old incidents were closed by the above-mentioned scenarios.

Hi,

data for comments and work_notes is stored in sys_journal_field

You can check for your incident record if there is any record in sys_journal_field with that comments or work notes value

if yes then it means it was closed by that scenario and then update the checkbox

Something like this

Ensure you give correct work_notes and comments text to find those records

var gr = new GlideRecord("incident");
gr.get("incidentSysId");

var rec = new GlideRecord('sys_journal_field');
rec.addEncodedQuery("name=incident^element=work_notes^valueLIKEclosed by scenario 1^ORvalueLIKEclosed by scenario 2");
rec.addQuery("element_id", gr.getUniqueValue());
rec.query();
if(rec.next()){
	
	// update your checkbox
	gr.u_checkbox = true;
	gr.update();
	
}

Regards
Ankur

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

Raghu Ram Y
Kilo Sage

@Reddy481 

1.) To auto close incidents, OOB one business rule is available.. in that add one unique additional comment..something like.. Incident automatically closed after 5 days in the Resolved state.

2.) Then navigate to "Incident" table and give filter condition like "*Incident automatically" then you will get all the results..

Note : Comment should be unqiue.