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

right ok that makes sense, there is presumably a business rule populating the comments from the sys_journal_field table on the activity log on the form. So how do i update comments without triggering other business rules on that form?!

 

OK so i can't figure out any way of updating journal entries with workflow set to false so i've worked around it as below. Thanks for the assistance.

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()){
updateComments(gr.getUniqueValue(), prbName);
gr.state = -8;
gr.problem_id = prbID;
gr.setWorkflow(false);
gr.update();
}
}

function updateComments(sysID, prbName){
var gr = new GlideRecord('incident');
if(gr.get(sysID)){
gr.work_notes.setJournalEntry('This record has been identified as a repeat Incident and has been linked with ' + prbName);
gr.update();
}
}

Greg42
Mega Guru

I would go for the sanity check first.

1 ) See if you have correct data for the test. Your query might not actually pick up the records you assume it will. Set a test and first confirm that you have those incidents in the loop.

2) For checking sys_journal_field table, make sure you checking same records. Again, journal fields might be added to other records than you assume.

3) Double check that account you are using can view the field.

4) Any other rules that might be blocking viewing or updating those particular records or run after your code runs?

If you really have a journal field of a record and nothing is visible there, then I would say a HI ticket.