Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Example of setJournalEntry(Object, String)

Tadz
Kilo Sage

Hi, how do we use setJournalEntry?

I tried setJournalEntry(current_record,'string i wanted');

is this wrong?

Thanks,

Tadz

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Cris,



You need to use it in following manner.


example as belows:



var fieldName = "work_notes"; // it can be work notes field or comments field


var incRec = new GlideRecord("incident");


  incRec.addQuery("sys_id", sysId);


  incRec.query();


  if(incRec.next()){


  incRec[fieldName].setJournalEntry("hello");


  incRec.update();


  }



format is as belows:


objectName[nameOfField].setJournalEntry("value you need to set");



Please mark this answer as helpful. This will work for sure.


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Cris,



You need to use it in following manner.


example as belows:



var fieldName = "work_notes"; // it can be work notes field or comments field


var incRec = new GlideRecord("incident");


  incRec.addQuery("sys_id", sysId);


  incRec.query();


  if(incRec.next()){


  incRec[fieldName].setJournalEntry("hello");


  incRec.update();


  }



format is as belows:


objectName[nameOfField].setJournalEntry("value you need to set");



Please mark this answer as helpful. This will work for sure.


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

Thanks for helpful post.

I would like to make an addition: If you add a user name to your code, you can define the journal entry's owner

objectName[nameOfField].setJournalEntry("value you need to set","user_name");

 

ie:

var vCloseStr = 'Change Cancelled as the state was New and the change has passed it\'s start date/time';

grCR['work_notes'].setJournalEntry(vCloseStr,'admin');

find_real_file.png

this code fails to execute for me...