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

gsmallridge
Kilo Contributor

i tried the code from the documentation:

 

notes = current.work_notes.getJournalEntry(-1);
      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]);

7 REPLIES 7

ccajohnson
Kilo Sage

I reformatted the code to include the appropriate curly brackets. I was successful with this:



var notes = current.work_notes.getJournalEntry(-1);


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]);


}



Let me know if you are still having difficulty.


The code worked fine as it was, omitting the curly brackets is still acceptable syntax.



The problem I'm having is with the 'getJournalEntry' method which returns an ampty string in the 'notes' variable.



I'm trying to search through the 'Activity' of an incident for specific text strings.


  1. Is the above code segment the right one to use for this?
  2. How can I do this if the above code doesn't retrieve the text that I need?

I used your code on my instance and it pulls the work notes just fine for me. The additional comments (comments) field also writes to the activity. Are you sure that what you are looking for was entered in the work notes?


Well, I can't get the method to return anything. I was hoping it was a shortcut to getting the records from 'Journal Entry' table.



So I created this function:



/**


* Gets all journal entries for this incident.


*


* @param incidentSysId


* @returns {String} - each journal entry is separated by a linefeed pair '\n\n'.


*/


function getActivity( incidentSysId )


{


      var journalString = "";


      var actObject = new GlideRecord('sys_journal_field');


      actObject.addQuery('element_id', incidentSysId);


      gsLog("incidentSysId: " + incidentSysId);


      //actObject.addQuery('element', "comment");


      //actObject.addQuery('name', 'task');


      actObject.query();


      if(actObject.next()) {


              gsLog("Journal entry: " + actObject.value);


              journalString = actObject.value;


              while( actObject.next())


              {


                      journalString += '\n\n' + actObject.value;


              }


      }


      return journalString;


}