Posting comments via REST API and getting their sys_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 06:42 AM
Hello!
From what I understand, the only way to post comments via the REST API is by editing the comment/work_notes field of the parent object in the adequate table (incident, problem, case etc.), and simply adding entries to sys_journal_field does not work. My question is, once I post the comment this way, what is the best and most accurate way to retrieve the posted comment id from the sys_journal_field table? My worries are namely that if I for example query by element_id and order by descending date of creation, there is still the possibility that another comment has been posted at the same time of after I posted my comment and I am getting the wrong comment id. Is there a good way to add the comment body to this query of the sys_journal_field table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 02:29 AM
What I want to do is either add a comment or update a comment via REST API. My issue is that if I add a comment via the Table API and directly change the sys_journal_field table, these entries won't be shown in the Activity Stream for the object these are comments are related to (incidents, problems, cases etc.). Therefore, the proper way to do it is by adding the comment via the incident/case/problem table and adding my comment to the comment or work_notes field. Here my issue however is how do I get the sys_id of the comment that was just added since in the response of the put/patch REST API call to the incident table where I edit some incident entry I only get the incident entry that was changed and not the sys_journal_field entry that was created for the actual comment/work note. This last part is important to me because I need to have the id of the comment I created via the REST API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2025 05:29 AM
You're right, Cody — directly inserting into sys_journal_field won’t work as it bypasses business rules and auditing. Updating the comments or work_notes field on the parent record (like incident) via the REST API is the recommended approach.
To reliably retrieve the sys_id of the newly posted comment, one method I've used is to immediately query the sys_journal_field table after the update using a combination of filters:
element_id = the record you updated
element = comments or work_notes
value = the exact comment body you posted
ORDERBYDESC on sys_created_on
This gives you a much more accurate match than relying on timestamps alone. It’s not bulletproof if the same comment body gets posted multiple times, but in most cases, this narrows it down well.
Alternatively, if you have control over the format of your comment, you could include a unique identifier (like a UUID or timestamp token) in the body, then search for that specifically. That way, you're guaranteed to get the exact match.
Hope this helps! Let me know if you've found any other clever workarounds.