Help me get the Journal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2024 10:32 AM
I created a Journal List to get the data from the addtional comments, but when I use the ServiceNow REST API it brings me everything empty, how can I get this data? I tried to get it directly from the addtional comments but it is an input journal, does anyone know how I can get this data?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2024 06:13 PM
You can use
var stream = new GlideSPScriptable().getStream('incident', 'dc6f1b6093ebf910099cfcf08bba1051');
to get all journal field related information as an object for any task based record.
It returns an object that looks (so stream would look) like:
{
"display_value": "INC0010027",
"sys_id": "dc6f1b6093ebf910099cfcf08bba1051",
"short_description": "ASDFASDFASDFASDF",
"number": "INC0010027",
"entries": [
{
"sys_created_on_adjusted": "18/07/2024 04:10:24",
"sys_id": "6011ec9c93abc210099cfcf08bba107b",
"login_name": "Developer",
"user_sys_id": "ca29292a2f2130100c8dd99df699b6dc",
"initials": "D",
"sys_created_on": "2024-07-18 01:10:24",
"contains_code": "false",
"field_label": "Additional comments",
"name": "Developer",
"value": "Comment 3",
"element": "comments"
},
{
"sys_created_on_adjusted": "18/07/2024 04:10:20",
"sys_id": "af01ac9c93abc210099cfcf08bba10df",
"login_name": "Developer",
"user_sys_id": "ca29292a2f2130100c8dd99df699b6dc",
"initials": "D",
"sys_created_on": "2024-07-18 01:10:20",
"contains_code": "false",
"field_label": "Additional comments",
"name": "Developer",
"value": "Comment 2",
"element": "comments"
},
{
"sys_created_on_adjusted": "13/02/2024 23:54:25",
"sys_id": "a92fd49893abc210099cfcf08bba10f5",
"login_name": "Developer",
"user_sys_id": "ca29292a2f2130100c8dd99df699b6dc",
"initials": "D",
"sys_created_on": "2024-02-13 21:54:25",
"contains_code": "false",
"field_label": "Work notes",
"name": "Developer",
"value": "Checklist created",
"element": "work_notes"
},
{
"sys_created_on_adjusted": "02/01/2024 15:29:20",
"sys_id": "b52fd49893abc210099cfcf08bba10fc",
"login_name": "Developer",
"user_sys_id": "ca29292a2f2130100c8dd99df699b6dc",
"initials": "D",
"sys_created_on": "2024-01-02 13:29:20",
"contains_code": "false",
"field_label": "Additional comments",
"name": "Developer",
"value": "ASDFASDFASDFASDF",
"element": "comments"
}
],
"user_sys_id": "ca29292a2f2130100c8dd99df699b6dc",
"user_full_name": "Developer",
"user_login": "developer",
"label": "Incident",
"table": "incident",
"journal_fields": [
{
"can_read": true,
"color": "transparent",
"can_write": true,
"name": "comments",
"label": "Additional comments"
},
{
"can_read": true,
"color": "gold",
"can_write": true,
"name": "work_notes",
"label": "Work notes"
}
]
}
You can than loop through stream.entries to find what you need and transform it to your needs.
You can also "do"
var stream = $gr.comments.getJournalEntry(-1);
which will return what you have in the screen-shots, a text along the lines of:
18/07/2024 04:10:24 - Developer (Additional comments)
Comment 3
18/07/2024 04:10:20 - Developer (Additional comments)
Comment 2
02/01/2024 15:29:20 - Developer (Additional comments)
ASDFASDFASDFASDF
but which will not be easy to parse, in case you don't want to use it as is.