Adding journal notes to incidents via script

Venjamin
Tera Contributor

I have an ask to update 300+ records. While this is doable, the ask includes adding notes to the update, which is always a little trickier. I'm not sure how to dotwalk or access the attached activity list to update it.

 

var gr = new GlideRecord('incident')

gr.addEncodedQuery('major_incident_state=accepted^hold_reasonIN13,12,14,16^incident_state=6')
gr.query();

while(gr.next()) { 
gr.setWorkflow(false);
gr.setValue('work_notes', '"Bulk VP Review RCA cleanup: All VPs were provided a list of RCAs in their orgs, identified by their teams as "Ready for Review".  VPs were given two weeks to review, and either request additional review, or the RCAs would be closed. Closing this RCA in accordance with that effort. Any open tasks will be marked Closed/Skipped; the RCA Management task was completed, but for purposes of the update it will reflect Closed/Skipped too."');
gr.setValue('u_origin_of_incident', 'notapp');
gr.setValue('incident_state', '7');
gr.setValue('hold_reason', '9');
gr.update(); }

 

I tried this version, but of course I discovered I was using outdated dictionary references - work_notes doesn't exist on the incident table. 

 

Does anyone know how to add notes via a background script? I'm also trying to close any related incident tasks, which shouldn't be as difficult, I think, but this was the big one I wanted to knock out first.  

2 ACCEPTED SOLUTIONS

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Venjamin 

 

setValue will not work on journal type fields,use gr['work_notes'] instead, so, your script should be:

 

 

var gr = new GlideRecord('incident')

gr.addEncodedQuery('major_incident_state=accepted^hold_reasonIN13,12,14,16^incident_state=6');
gr.query();

while(gr.next()) { 
gr.setWorkflow(false);
gr['work_notes'] = 'Bulk VP Review RCA cleanup: All VPs were provided a list of RCAs in their orgs, identified by their teams as "Ready for Review".  VPs were given two weeks to review, and either request additional review, or the RCAs would be closed. Closing this RCA in accordance with that effort. Any open tasks will be marked Closed/Skipped; the RCA Management task was completed, but for purposes of the update it will reflect Closed/Skipped too.';
gr.setValue('u_origin_of_incident', 'notapp');
gr.setValue('incident_state', '7');
gr.setValue('hold_reason', '9');
gr.update(); 
}

 

 

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks,

Karan

 

View solution in original post

Karan Chhabra6
Mega Sage
Mega Sage

@Venjamin  - that's because you've used gr.setWorkflow(false), worknotes are stored in 'sys_journal_field' table and they are inserted there via some OOB business rule.

If you remove 'gr.setWorkflow(false)' from the script, work notes would show up.

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

View solution in original post

5 REPLIES 5

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Venjamin 

 

setValue will not work on journal type fields,use gr['work_notes'] instead, so, your script should be:

 

 

var gr = new GlideRecord('incident')

gr.addEncodedQuery('major_incident_state=accepted^hold_reasonIN13,12,14,16^incident_state=6');
gr.query();

while(gr.next()) { 
gr.setWorkflow(false);
gr['work_notes'] = 'Bulk VP Review RCA cleanup: All VPs were provided a list of RCAs in their orgs, identified by their teams as "Ready for Review".  VPs were given two weeks to review, and either request additional review, or the RCAs would be closed. Closing this RCA in accordance with that effort. Any open tasks will be marked Closed/Skipped; the RCA Management task was completed, but for purposes of the update it will reflect Closed/Skipped too.';
gr.setValue('u_origin_of_incident', 'notapp');
gr.setValue('incident_state', '7');
gr.setValue('hold_reason', '9');
gr.update(); 
}

 

 

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks,

Karan

 

Thank you for your info. I will say, though it seemed to insert into the journal entry, it's not showing up in the activities / notes section on the individual incident it should be attached to. 

Hi @Karan Chhabra6 ,

 

Same like i wanted to update the work notes of requested item with gr.setWorkFlow(false) in the script. But the workflow comments are not updating

 

 var gr = new GlideRecord("sc_req_item");
    gr.addQuery("sys_id", data.sys_id);
    gr.query();
    if (gr.next()) {
        var action = input.action;
        if (input.action == 'canceledReq') {
 
            var oldWorkflow = new Workflow();
            oldWorkflow.cancel(gr);
 
            gr.stage = "Request Cancelled";
            gr.state = '8';
 
            gr.active = "false";
 
     gr.setDisplayValue('comments', 'Cancelled by Requester with comment: ' + input.cancelledComments);
 
gr.setWorkflow(false);
            gr.update();
            
 
        }

Karan Chhabra6
Mega Sage
Mega Sage

@Venjamin  - that's because you've used gr.setWorkflow(false), worknotes are stored in 'sys_journal_field' table and they are inserted there via some OOB business rule.

If you remove 'gr.setWorkflow(false)' from the script, work notes would show up.

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!