How to Log Incident State Changes in Additional Comments?

BetalA
Tera Contributor

I created a Business Rule to log state changes in the Additional Comments section when an incident is updated. 

Business Rule Details:

When to Run:

  • When: Before an update is checked

Conditions:

  • State is New, In Progress, On Hold, Resolved
  • OR State is Canceled

Script:

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

    // Add your code here

    var stateChagneMsg = "The Incident State has been changed to  " + current.getDisplayValue("state");

    current.comments = stateChagneMsg;

})(current, previous);

 

Expected Behavior:

If the incident is canceled, all messages logged by this business rule should appear in the Additional Comments section of the activity stream.

 

Questions:

  1. Is there a better way to log only state changes?
  2. How can I make sure that if the incident is canceled, all messages logged by this rule appear in Additional Comments?
1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @BetalA,

 

Similar to @Dr Atul G- LNG's thought process, can you expand on the 'why' or requirement of displaying the state change within Additional comments?

Out Of Box (OOB), ServiceNow provides the ability to display the state change (as well as other field value changes) in the same journal field area as the additional comments - see below screen shot.

However with the key difference, these changes are not populated in the additional comments and therefore not 'customer visible'. Point to note, Additional comments OOB trigger notifications and serve a difference purpose. Primarily they are to communicate across teams and/or customers.

 

Best practice would be to display the state change via the interactive filter as shown below:

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.




Thanks, Robbie

 

Screenshot 2025-02-05 at 10.28.52.png

View solution in original post

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

H i @BetalA 

 

Additional comments are used to communicate to end user and there is no value to showing the state movement to end user in this.  May i know what is your business case for this?

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Robbie
Kilo Patron
Kilo Patron

Hi @BetalA,

 

Similar to @Dr Atul G- LNG's thought process, can you expand on the 'why' or requirement of displaying the state change within Additional comments?

Out Of Box (OOB), ServiceNow provides the ability to display the state change (as well as other field value changes) in the same journal field area as the additional comments - see below screen shot.

However with the key difference, these changes are not populated in the additional comments and therefore not 'customer visible'. Point to note, Additional comments OOB trigger notifications and serve a difference purpose. Primarily they are to communicate across teams and/or customers.

 

Best practice would be to display the state change via the interactive filter as shown below:

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.




Thanks, Robbie

 

Screenshot 2025-02-05 at 10.28.52.png

BetalA
Tera Contributor
Sorry, my bad. I did not explain the requirement clearly.

If the incident state changes to "Closed" or "Canceled," all activities should be logged in the last comment before the incident is closed. This ensures that anyone reviewing a closed or canceled incident has a complete summary of all activities in a single comment.

Hi @BetalA 

 

So, are you suggesting tracking all changes from start to finish in the last Worknote? If that’s the case, I wouldn’t recommend it. It’s not really feasible because activity gets stored in the sys_audit table, and pulling all changes from the logs could impact system performance. Plus, ServiceNow already organizes logs in chronological order, so the changes are already being tracked effectively.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************