Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

is it possible to Read Data in Comments using glideRecord?

aashishdasari
Tera Expert

Hi All,

I want to read data from the Comments and Work Notes field in Task. The Data is as follows:

find_real_file.png

I want to read it using the GlideRecord. Can anyone tell me how will I be able to retrieve the data.

4 REPLIES 4

ark6
Mega Guru

You need to use getJournalentry() function as these are journal fields.



See the post below


current.work_notes.getJournalEntry(-1); returns an empty string


Harsh Vardhan
Giga Patron

Hi Aashish,



Please find the details below.



3.27 getJournalEntry(int)

Gets either the most recent journal entry or all journal entries.


Parameters: -1: get all journal entries, 1: get the most recent journal entry.


3.27.1 Output Fields

Returns: (Sting) For the most recent entry, returns a sting that contains the field label, timestamp, and user display name of the journal entry. For all journal entries, returns the same information for all journal entries ever entered as a single string with each entry delimited by "\n\n".


3.27.2 Example

var notes = current.work_notes.getJournalEntry(-1); //gets all journal entries as a string where each entry is delimited by '\n\n' 
var na = notes.split("\n\n");                                             //stores each entry into an array of strings  
for (var i = 0; i < na.length; i++)
gs.print(na[i]);


Get comments details through glide record



function cdetails(iId)


{  


var test= "";  


      var cm= new GlideRecord('sys_journal_field');  


cm.addQuery('element_id', iId);  


      gs.log("SysId: " + iId);            


      cm.query();  


      test= '';          


      while( cm.next() ) {


             


              test += cm.sys_created_on + ' - ' +   cm.sys_created_by + ' (' + cm.element + ')\n' + cm.value + '\n\n';


             


      }


return test;


}


We also need to get the specific value of comment details as well but we are doing this on a Service Portal widget.



How would this work on the server side code if for example we just need to get the sys_created_on of the most recent journal entry?


Dan51
Giga Contributor

Is it possible to see the code behind getJournalEntry()? This returns a string but instead I want to take the 4 bits of data from this string and make it into an object. Something like the object below.

 

{

created: 'x',

created_by: 'y',

content: 'z'

sys_id: '0000000000'

}

 

Is this possible without using sub string as I'm unsure how long the text will be in the fields?