Incident Resolution notes should be copied to problem worknotes once the incident is resolved

VijayKummamuru
Tera Expert

VijayKummamuru_0-1747367767149.png

VijayKummamuru_1-1747367793119.png

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

    // Add your code here
    var probGr = new GlideRecord('problem');
    probGr.addQuery('first_reported_by_task', current.sys_id);
    probGr.query();

    if (probGr.next()) {
        probGr.work_notes = current.close_notes;
        probGr.update();
    }

})(current, previous);
 
 
Above BR not working 
 
3 REPLIES 3

shantanu_patel8
Mega Guru

Hi @VijayKummamuru 

 

Your business rule script is looking good and ideally it should have updated to problem record.

 

I can see that there be issue with the "first_reported_by_task" field. Can you check if this field is already populated by the Incident you are trying to close. You can also add log after "probGr.query();" something like "gs.info(prbGr.getEncodedQuery()+' rows matched '+probGr.getRowCount());" to know if the query is fetching the right values.

 

Please mark the answer helpful and correct if it resolves the issue. Happy scripting 🙂

 

-Shantanu

Rishiraj14
Giga Expert
Your code has an error, kindly use this updated code it will work,

// Add your code here
    var probGr = new GlideRecord('problem');
    probGr.addQuery('sys_id', current.problem_id);
    probGr.query();

 

    if (probGr.next()) {
        probGr.work_notes = current.close_notes;
        probGr.update();
    }

 

})(current, previous);


Hope so the solution had helped you, if you face any further error please update.
If you find it helpful kindly hit the like button and close this question, Thanks

Ranjit Nimbalka
Mega Sage

Hi @shantanu_patel8,

You might consider adding an additional condition in your Business Rule to ensure that the Problem ID is not empty, which will help avoid unnecessary processing.

Also, the issue might be related to the use of the first_reported_by_task field. Instead, you can try the script below that directly uses the problem_id reference field:

 

(function executeRule(current, previous) {

// Ensure the Problem record is linked and available
var probGr = new GlideRecord('problem');
if (probGr.get(current.problem_id)) {
 probGr.work_notes = current.close_notes;
probGr.update();
}

})(current, previous);

 

 

Regards,

Ranjit