- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2023 03:01 AM - edited 04-22-2023 03:02 AM
Hi
How can I achieve the above in a custom action?
I have tried the following code that I found on another post here but I'm not sure what the inputs/outputs would be as whatever I try throws an exception:
Code:
(function execute(inputs, outputs) {
// ... code ...
var je = new GlideRecord('sys_journal_field');
je.addQuery('element','comments');
je.addQuery('element_id',current.sys_id.toString());
je.orderBy('sys_created_on','ASC');
je.setLimit(1)
je.query();
if(je.next()){
gs.info('First comment: ' + je.value.toString());
}
})(inputs, outputs);
Exception
Error: Cannot read property "sys_id" from null,Detail: Cannot read property "sys_id" from null
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2023 06:19 AM
@ thanks for the reply - I managed to get this working with a flow variable using
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2023 04:10 AM
Hi @ray evans ,
Seems like there's an issue with line 5, the code in script action does not have access to the current object, hence it is showing up as null.
please add sys_id as one of the inputs and then use it in the code like this:
(function execute(inputs, outputs) {
// ... code ...
var je = new GlideRecord('sys_journal_field');
je.addQuery('element','comments');
je.addQuery('element_id',inputs.sys_id.toString());
je.orderBy('sys_created_on','ASC');
je.setLimit(1)
je.query();
if(je.next()){
gs.info('First comment: ' + je.value.toString());
}
})(inputs, outputs);
If my answer has helped with your question, please mark it as correct and accepted solution.
Thanks!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2023 06:16 AM
Hi ray,
it looks like your current object is null in this line:
je.addQuery('element_id',current.sys_id.toString());
You need to define an input in the action designer first - either a reference you can access using inputs.task.sys_id or a sys_id string: inputs.sys_id - so that line would instead look like this depending on the name of your input
je.addQuery('element_id',inputs.sys_id.toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2023 06:19 AM
@ thanks for the reply - I managed to get this working with a flow variable using

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2023 06:59 AM
Hi,
There are a couple of different ways you can solve this, either you can continue on this path by query the sys_journal_field and get the results that way, or you could go with the method of retrieving the latest journal entry by using the GlideRecord method of .getJournalEntry(1)
I'll be providing a bit more extensive answer later on using the second option, but for now, the issue in your script is that the object "current" is not defined in the script.
You need to replace it by some input into your Flow action, perhaps a sysID of the input of the record would do?
Then the script would look something like below:
(function execute(inputs, outputs) {
var je = new GlideRecord('sys_journal_field');
je.addQuery('element', 'comments');
je.addQuery('element_id', inputs.your_input_variable_name.toString());
je.orderBy('sys_created_on', 'ASC');
je.setLimit(1)
je.query();
if(je.next()) {
gs.info('Most recent comment: ' + je.getValue('value'));
outputs.your_output_variable_name = je.getValue('value');
}
else{
outputs.your_output_variable_name = ''; // no record found, set empty output
}
})(inputs, outputs);