additional comments are not captured when update filed values via business rules

hemanth810620
Tera Contributor
Issue: When manually updating the "state" field on the incident form, the changes are captured in the "Activities(additional comments- Field Changes)".
However, when the "state" field is updated programmatically based on conditions (via Business Rule), so the update changes are not captured in the "Activities(additional comments- Field Changes)".. 
 
Issue: When manually updating the 'state' field in the Incident form, the changes are correctly captured in the Activities(additional comments- Field Changes). However, when the 'state' field is updated based on conditions (e.g., via business rules), the update is not reflected in the Activity Logs or Comments section. The changes are being successfully applied to the record, but no log entry is created, leading to incomplete tracking of changes.
 
Impact: This causes incomplete logging in the Activity Log and makes it difficult to track changes made programmatically.
 
Expected Behavior: Changes to the "state" field should be logged in the Activity Log regardless of whether they are made manually or programmatically.
 
Steps to Reproduce:
1. Update the "state" field manually - logs are captured in Activities(additional comments).
2. Update the "state" field programmatically using a script condition - Activities(additional comments) are missing.
 
BR Script:
 
When = additional comments --> Changes
 
(function executeRule(current, previous /*null when async*/ ) {
    // Check if a comment was added
   // if (current.comments.changes()) {}
        // Verify if the comment is from the requester (opened_by)
        if (current.opened_by == gs.getUserID()) {
            // Check if the state is Resolved (assuming states)
            if (current.state == 6 || current.state == 3 || current.state == 4 || current.state == 5 || current.state == 😎 {
                // Reopen the incident by setting the state to Active (2)
 
                current.state = 2;
current.short_description="testing--";
current.setWorkflow(false);
                current.update();
 
                current.setWorkflow(true);
            }
        }
    
})(current, previous);

 

7 REPLIES 7

hemanth810620_0-1734015734134.png

 

comments updated, but emails got trigger two times, because of current.update();
if i added this line(current.setWorkflow(false)), comments not updating, Email triggering one time(state is active -> email triggering) 

Runjay Patel
Giga Sage

Hi @hemanth810620 ,

 

Try like this.

// Temporarily disable workflows for controlled updates
            current.setWorkflow(false);
            current.setForceUpdate(true); // Force the update to log changes
            current.update();

            // Re-enable workflows after update
            current.setWorkflow(true);

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

                current.state = 2;
                current.setWorkflow(false);
                current.setForceUpdate(true);
                current.update();
                current.setWorkflow(true);

Not working 
State updated but comments are not updated