setJournalEntry isn't working as expected

Dubz
Mega Sage

Hi All,

We have a business rule creating Problem tickets automatically when an incident is raised on the same CI or service offering 3 times or more in the space of 30 days. I am using the below function to update incident tickets with their master problem tickets.

The issue is, the 3rd ticket raised is correctly updated with a comment saying 'this was linked to this problem' but the preceding incidents aren't. A record is added to the sys_journal_field table with the correct element, element_id and value but that journal entry is not being reflected on the incident record. The other field values on the incident, problem_id and state, are correctly updated as well. 

function updateProblemID(prbID, prbName, faultItem){

var qry = 'opened_atONLast 30 days@javascript:gs.beginningOfLast30Days()@javascript:gs.endOfLast30Days()^u_ticket_type=Incident^close_codeNOT INMerged,Duplicate^ORclose_codeISEMPTY^problem_idISEMPTY^service_offering=' + faultItem + '^ORcmdb_ci=' + faultItem;

var gr = new GlideRecord('incident');
gr.addEncodedQuery(qry);
gr.query();

while(gr.next()){
gr.state = -8;
gr.comments.setJournalEntry('This record has been identified as a repeat Incident has been linked to ' + prbName);
gr.problem_id = prbID;
gr.setWorkflow(false);
gr.update();
}
}

I've tried gr.comments = 'string value'; and gr[comments].setJournalEntry('string value'); but neither works, each adds a record to the sys_journal_field but that comment is not shown on the activity log on the incident form.

 

1 ACCEPTED SOLUTION

Hi David,

Your code worked for me if i remove gr.setWorkflow(false);

View solution in original post

7 REPLIES 7

Thanks but yeah, i've been through both of those links already. I've tried each method of adding a comment and each one adds a record to the sys_journal_field table as required but that record is then not shown on the incident.

Hi 

gr['comments'].setJournalEntry('This record has been identified as a repeat Incident has been linked to ' + prbName);

 

would you mind trying this as is? Because in the question you posted i see you have no '' mentioned. Try with this once.

Hi David,

Your code worked for me if i remove gr.setWorkflow(false);