The CreatorCon Call for Content is officially open! Get started here.

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

Karthik Reddy T
Kilo Sage

Hello Siva ,



Use the below sample code and try.



var gr = new GlideRecord('sys_user');


gr.get('user_name', "System Administrator");



var ou = gs.getSession().impersonate(gr.sys_id);


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


current.update();


gs.getSession().impersonate(ou);


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

Hi Karthik Reddy



Thanks for your response



I tried this & it's working but getting the given error,



find_real_file.png


But incident has been created successfully.


Please use setJournalEntry() to avoid these errors.


Make sure you do not include current.update() in a before insert business rule.



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

hi Anna Silva,


Paul's solution is way to go; if that too didn't work then try my solution of inserting a record directly on to sys_journal_field table.