Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Help me get the Journal

Arthur Sanchez
Giga Guru

Captura de tela 2024-07-17 142949.pngCaptura de tela 2024-07-17 143011.pngCaptura de tela 2024-07-17 143055.png

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?

1 REPLY 1

-O-
Kilo Patron

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.