[Solved] Adding comments and work notes via JSONv2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2014 06:55 AM
Hi,
Solution posted at the end.
Apologies for the length of this; I want to be thorough in what I've tried.
I'm struggling to INSERT comments and work notes for incidents via JSONv2. The user account I am using for this is the creator of the incident and can edit comments and work notes through the web interface without issue.
The following works for a JSONv2 GET request to query for an incident:
Uri Format: https://instancename.service-now.com/incident.do?JSONv2&sysparm_query=number=INC1234567
(it also works when using sys_id=580b112cf95a6500cf462e82aa6dfe1b )
It returns data for the incident to my script, and is visible in a web browser.
I have successfully updated the following fields using a JSONv2 POST request:
- u_alternate_contact
- u_machine_name
Uri Format: https://instancename.service-now.com/incident.do?JSONv2&sysparm_query=number=INC1234567&sysparm_acti...
Example JSON: { "u_alternate_contact": "Contact pushed via PowerShell" }
Using the above Uri format however, adding comments/work notes doesn't work.
After some reading around on other threads it seemed I should be adding these to sys_journal_field, performing the match on this table by using sys_id from the incident in incident.do, and using that for element_id. Testing this via a JSON GET request:
Uri Format: https://instancename.service-now.com/sys_journal_field.do?JSONv2&sysparm_query=element_id=580b112cf9...
... returned all existing work notes and comments for the incident via both the web UI and within my script. The comments/work notes that I tried to POST to incident.do were not visible either in the incident.do table or this. The only comments / work notes visible are those added via the web interface, so I suspect the POST to incident.do is definitely not working.
Minor success:
Attempting to update sys_journal_field.do:
Uri Format: https://instancename.service-now.com/sys_journal_field.do?JSONv2&sysparm_action=update&sysparm_query...
JSON:
{
"element": "work_notes"
"name": "task"
"value": "This is a work note added via PowerShell"
}
Rather than INSERT a record, this UPDATED every result (2 x work note, 1 x comment) to become a work note with the value "This is a work note added via PowerShell".
I tried sysparm_action=insert instead, but this didn't change anything.
At the moment the only thing I can think to do (somehow) is retrieve the existing values for comments and work notes in JSON format, append a new one, and then sysparm_action=update / POST the whole thing back. This is far from ideal however.
Help much appreciated!
Regards,
Robin
Solution to insert a new work note:
I had to use INSERT to sys_journal_field.do table as mentioned above, but using the sysparm_query=element_id=xxxxxxxxxxxxx is not required.
However, element_id must be specified in the JSON object, and this is the incident's sys_id value.
Uri Format: https://instancename.service-now.com/sys_journal_field.do?JSONv2&sysparm_action=insert
JSON:
{
"element": "work_notes"
"element_id": "580b112cf95a6500cf462e82aa6dfe1b"
"name": "task"
"value": "This is a work note added via PowerShell"
}
To insert a comment it would be "element": "comments"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2014 09:32 AM
@RobinM
I was looking at this too because I was finding same issue however your fix didnt' seem to work.
It would insert a record in the sys_journal_field table with the other work_notes in my case but would not show up on the form.
This should be a issue logged on HI if it isn't already.
I did find that if I reverted to using the JSON api instead of the JSONv2 this worked perfectly for me if I just included the journal field in the initial json obj.
Example so we are all on the same page;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2016 06:58 AM
Thanks,
It worked perfectly for me.....! with JSONv2 as well
earlier work_notes and comments were not visible when inserted using sys_journal_field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2014 09:39 AM
I marked this discussion as a question so you can actually mark your solution as the correct answer and it will be marked as answered
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2015 02:43 AM
Hi,
I tried to add a comment to a previously created incident with the solution provided by Robin M but I have the following response :
{
"error": "Insufficient rights to insert records from the table: sys_journal_field",
"reason": null
}
Does the user sending the request need specific role ?
Mine has "rest_service" and "itil".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 05:13 AM
Did you ever get a response to this or figured it out? I have the same issue. I can create the entries in the journal table but they don't show up in the UI or I get insufficient rights.