Business Rule - Add automatic comments as admin

SNOW User8
Giga Guru

Hi All,

Want to add automatic comments in an incident additional comments field when new incident is inserted.

My issue is, added comments are updated by the current user, But I want it as Admin. Since it is an automatic comments.

How to do that ?

If anyone know the solution kindly, help me.

Business Rule:

Before insert,

Script:

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

// Add your code here

current.comments = "Thank you for contacting TEST";

})(current, previous);

The comments here added by the current user, I want it as System Administrator

find_real_file.png

Thanks & Regards,

Anna Silva

24 REPLIES 24

I just did some testing and found some unexpected behaviour:



  • Before (Insert True, Update False) - comment is always made as currently logged in user
  • Before (Insert False, Update True) comment is made as admin user
  • After (Insert True, with current.update() ) comment is made as admin user


So, if you want this to work on insert, you must create an After Business Rule as follows:



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


current.comments.setJournalEntry('Thank you for contacting TEST', 'admin');  


current.update();


})(current, previous);



I must stress that setJournalEntry is the only supported way to meet your requirement.



This function does not work as documented on before insert business rules.


I would consider this a bug and raise with ServiceNow support on HI.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Hi Paul,

I tired this and it worked. However, the name on the email notification received by end user is still the one who triggered the business rule even though when you view the activity feed it shows as the one we set using setJournalEntry. Any ideas?

Yes, the record is still being updated by the user.

You'll need to cater for this in your notification.

One easy way is to ensure 'Send to event creator' is FALSE. 

You may need to select the Advanced View UI Action to see this field.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

What we need to achieve to make the automatic comment be shown as added by the system which the setJournalEntry solution achieved. However, this is just the case on the activity stream and not on the email notification, why is that the case?

So basically the user will see it as added by system on the website but when she receives an email notification it will be shown as added by a specific person. You'll understand how the user will get confused by this.

When update() is run in a business rule, the system is not updating the record, the user is.Alas, the record is updated by the currently logged in user.
The setJournalEntry bit is effectively only cosmentic.

That said, my solution given will stop the notification from going out to the user. The user is effectively triggering the business rule, in turn triggering the Notification.

Setting 'Send to event creator' to false will mean the user will not receive a notification when they add something to the comments field, or make an update that triggers an addition to the journal.

It will fix your issue.

 


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022