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

Need to update the update comment person name in to system.

Venky Kshatriy2
Tera Contributor

I would to made by the comment by the system instead of logged in user 

 

var vk = gs.getUserDisplayName();
 gs.addInfoMessage(vk);
 var gh = new GlideRecord('sc_req_item');
 gh.addEncodedQuery("cat_item=060f3afa3731300054b6a3549dbe5d3e")
 gh.query();
 while (gh.next()) {

     var vc = gh.comments.getJournalEntry(1);
     gs.addInfoMessage(vc);

 if (vc && vc.indexOf(vk) != 1) {
       
    var kl = gh.comments.setJournalEntry(1, vc.replace(vk, "system"));
    gs.addInfoMessage(kl);

 }
}    
 
 
 
after  this script running  in to background i am getting undefined...
 
 
if any one know about this, could u please help on this..... 
4 REPLIES 4

Dr Atul G- LNG
Tera Patron

May i know what is business case here? If a comment added by a user, must show user name not system.

*************************************************************************************************************
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/dratulgrover [ Connect for 1-1 Session]

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

My Requirement is to change the user name in to system

 

is it possible to change user name to system.

 

Hi @Venky Kshatriy2 

 

You can do , but it is not a valid requirement. 

 

https://www.servicenow.com/community/service-management-forum/how-to-update-comments-without-mention...

 

*************************************************************************************************************
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/dratulgrover [ Connect for 1-1 Session]

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

Anubhav24
Mega Sage

Hi @Venky Kshatriy2 ,

 

In your indexOf condition "if (vc && vc.indexOf(vk) != 1)" it should be "if (vc && vc.indexOf(vk) != -1)" , if you want the control to enter if condition because indexOf() method returns the position of the first occurrence of a value in a string. If the string is not present it returns -1.

Try and let us know if it works.

 

Please mark correct/helpful if my response helped you.