How to get journal content in scoped application?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2015 12:35 PM
I have a scoped application in Fuji with a custom table. This table has a journal field that I would like to read the contents of in script. I've found the getJournalEntry method, but this is denied when run:
"Function getJournalEntry is not allowed in scope my_app"
How do I read the journal field on my table? Thanks,
Noah
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2015 12:40 PM
Scripting in Scoped Applications - ServiceNow Wiki
Might find something interesting here, particularly the 3.2.3 Calling a Global Script from Another Application Scope piece.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2015 06:50 PM
Thanks Mike. I didn't find an equivalent method, but did develop a solution that works by querying the Journal Entry table directly. Each journal entry appears to be there with a reference to the parent record sysid and the journal field name. This function gets the most recent entry:
getLastJournalEntry: function(parentSysId, fieldName){
// Get most recent record from Journal List table
var journalRecord = new GlideRecord('sys_journal_field');
journalRecord.addQuery('element_id', parentSysId);
journalRecord.addQuery('element', fieldName);
journalRecord.orderByDesc('sys_created_on');
journalRecord.query();
if(journalRecord.next()) {
return journalRecord.value;
}
}
Then, to use:
var lastEntry = this.getLastJournalEntry(parentRecord.sys_id, "log");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 04:51 AM
This was super-helpful, noahstahl
I adapted it a little bit to behave more like the (forbidden) baseline getJournalEntry() method:
function getJournalEntry (recordId, fieldName, count) {
if (gs.nil(count)) { count = 1; }
var output = [];
var je = new GlideRecord('sys_journal_field');
je.addQuery('element_id', recordId);
je.addQuery('element', fieldName);
je.orderByDesc('sys_created_on');
je.query();
var index = 0;
while (je.next() && (count==-1 || index < count) ) {
output.push(je.value+'');
index++;
}
return output;
}