We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

BR that only runs when comments changes copy to task

Mounika30
Kilo Sage

How to create a  BR that only runs when comments changes but state doesn't change. It should copy the comments to the task.

3 REPLIES 3

Harish KM
Kilo Patron

Hi @Mounika30 your BR should be after update and condition must be

additionalcomment CHANGES // this would trigger only when comments are updated

 

and SCRIPT:

var task = new GlideRecord('sc_task');

task.addQuery('request_item',current.sys_id);

task.query();

while(task.next())

{

task.comments = current.comments.getJournalEntry(1);

task.update();

}

Regards
Harish

Hi @Mounika30 Is your issue resolved. Please accept my solution if it helped you

Regards
Harish

Maddysunil
Kilo Sage

@Mounika30 

You can write Asynch -update business rule with below code:'

 

(function executeRule(current, previous /*null when async*/) {
    // Check if the 'comments' field has changed
    var commentsChanged = current.comments != previous.comments;
    
    // Check if the 'state' field has remained the same
    var stateRemainedSame = current.state == previous.state;
    
    // Run the rule only when comments change but state remains the same
    if (commentsChanged && stateRemainedSame) {
        // Retrieve the associated task (e.g., Incident's parent task)
        var task = new GlideRecord('task_table_name');
        task.get(current.parent.sys_id); // Modify this to match your scenario
        
        // Update the 'work_notes' field on the task with the comments from the current record
        task.work_notes = current.comments;
        task.update();
    }
})(current, previous);

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks