- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2023 09:18 AM
Hi,
I am trying to run a glide record onto the sys_journal_field table to get the last 2 results. I then need to see if they are comments or work notes and post them into the correct field across an API. I have run into some issues with my script, I can get it to log the values but can't seem to get it to return the values.
Here is the script I'm running;
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2023 06:59 AM
Having attended a lab at Knowledge I was introduced to ServiceNow Remote Instance spoke - this has an action called Look up Worknotes/comments which does all this work for me and solves my issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2023 09:29 AM
It looks like you are returning an array of objects. Have you considered using JSON.stringify on it and returning a string?
Have you thought about using a business rule that runs when the comments is update and another one for when the work notes is updated and then triggering the update to the other system from there? You can then just use getJournalEntry to get the last one and pass it to whatever you are using to send the data to the other system.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2023 09:51 AM
Hi Drew,
I will try the JSON.stringify and let you know how I get one. I haven't done the business rule approach as I had built the API to run off a flow.
Thanks,
Rob

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2023 09:57 AM
The create an action that you pass in a GlideRecord and it will have two outputs. One is comment and the other is work note. Then use GlideRecord.comment.getJournalEntry(1) and GlideRecord.work_note.getJournalEntry(1) to set the outputs. No reason to be anymore complicate than that. You can then use the output of your action in the other parts of the flow/subflow.
You can also just build the flow as a subflow and pass in the values and then use the flow API to call it from a BR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2023 05:09 AM
Hi Drew,
Thank you for the suggestion but I'm struggling with setting up this action. In the inputs section which option am I putting for type, 'Glide var', as I can't choose records.sys_journal_field? I have also tried just setting the input to the sys_id of the updated incident and then running a script step with the glide record in it but again that is still returning no values?
(function execute(inputs, outputs) {
var element = '';
var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id', inputs.number_sys);
gr.setLimit(2);
gr.orderByDesc('sys_created_on');
gr.query();
while(gr.next()){
element = gr.getValue('element');
if (element === 'comments') {
outputs.comment = gr.getJournalEntry(1);
} else if (element === 'work_notes') {
outputs.work_note = gr.getJournalEntry(1);
} else {
// Handle the case where the journal entry is neither a comment nor a work note
// For example, you could set another output to the journal entry text
outputs.other = gr.getJournalEntry(1);
}
}
})(inputs, outputs);
Thanks in advance of any further guidance.
Rob