work notes from problem_task to problem is not working at all.

tghadage124
Tera Contributor

hi all , 

 

var problemRec = new GlideRecord('problem');
problemRec.addQuery('sys_id', current.problem);
problemRec.query();
if(problemRec.next()) {
        problemRec.work_notes = current.work_notes.getJournalEntry(1);
problemRec.update();
 
this is the code for the same.  
 
whenever i am tying infrom problem_task to problem record its it going like this in loop 
please look into it. once if you have answer do let me know.
 
Screenshot (459).png
4 REPLIES 4

Rajesh Chopade1
Mega Sage

hi @tghadage124 

 

Looks code is potentially causing a loop between the 'problem_task'  and problem records. This could be happening because you're modifying the problem record's work notes in response to a change in the problem_task record, and that update might trigger an event that starts the process over again.

 

Could you try following code once :

var problemRec = new GlideRecord('problem');
problemRec.addQuery('sys_id', current.problem);
problemRec.query();

if (problemRec.next()) {
    // Check if the work notes have already been updated to avoid recursion
    if (!problemRec.u_processed) {
        // Add the journal entry to work notes
        problemRec.work_notes = current.work_notes.getJournalEntry(1);
        
        // Set a flag to avoid recursion
        problemRec.u_processed = true;
        
        // Update the problem record
        problemRec.update();
    }
}

 

I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

Rajesh

 

Brad Bowman
Kilo Patron
Kilo Patron

Do you have Filter Conditions on the Business Rule when Work notes changes?  Do you have any Business Rules running on the problem table that is doing anything with work_notes?

-O-
Kilo Patron
Kilo Patron

Is there maybe a business rule that does the reverse: when the work notes on the problem are added, it copies those to all problem tasks?

shivatmika_19
Tera Guru

Hi @tghadage124,

You can try the below code

BR: After update

Condition: work notes changes

table: problem_task

Script:

(function executeRule(current, previous /*null when async*/) {

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var problemRec = new GlideRecord('problem');
problemRec.addQuery('sys_id', current.problem);
problemRec.query();
if(problemRec.next()) {

var workNotes = current.work_notes.getJournalEntry(1);

if(workNotes.indexOf(current.number+': ') == -1){

problemRec.work_notes = current.number+': '+workNotes;
problemRec.update();
}
}
else{

gs.addInfoMessage('No associated problem record exists for the problem task');
}
 
})(current, previous); 
Note: you can modify the string for stopping the loop (i used [record number : ---> e.g., PTASK1234 🙂