- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2015 10:17 AM
I am trying to add to the comments on an incident via the REST API, but can not clearly see how to do this. If I post a new incident and add to the "comments" field, it does not persist. Does anyone know of a way to do this? Thanks.
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2015 09:30 AM
Hi Brad - did you actually check the incident that was created? The example page does work. What you are seeing in the response is because of the nature of the Comments and Work notes fields. They don't actually store the comments you put in an incident, so when the response says: comments: "" - that should not be taken as there are no comments for that incident.
What happens is when you post to the comments field, it is then stored over in the sys_journal_field table with a relationship back to the incident. The activity formatter on the incident form goes and retrieves all the comments (and other field you tell it too) and presents them on the form in date order. The trick to getting the comments back via the GET - is adding &sysparm_display_value=true which they do actually have in the screenshot, but don't state it (that I noticed).
Let me know if this doesn't make sense.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2015 01:43 PM
You are most welcome Brad.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2015 12:22 PM
Additional comments are stored in sys_journal_field table with the sysid of the incident (or whatever for that matter) in the element_id field. Now you could probably use rest to go directly against that table, but I don't think I need to explain the numerous reasons why that's a bad idea. I think the best approach would be to use a business rule or WS transform map that envokes setJournalEntry(). http://wiki.servicenow.com/index.php?title=GlideElement#setJournalEntry.28Object.2C_String.29
-tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2015 12:50 PM
Tim,
I am currently working on a generic/standarized integration to ServiceNow and will only be able to interact via the REST API. I have seen suggestions to go directly against the sys_journal_field table, though per your comment I am not aware why that would be a bad idea (Admittedly my familiarity with ServiceNow is limited). If it ends up being that there is no good way to create comments via the API, then that is what I will have to deal with, but I thought I would turn here to find out. I appreciate your response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2015 01:00 PM
Any table prefixed with "sys_" is a system table. This one in particular is a very special as it crosses across dozens of tables with no formal relationship between them. We frequently pull data from this table for text mining and other analytics but it's one of those that I would think it would be a very bad idea to put data into.
A cleaner way to approach would be to build out an Import Set REST API - http://wiki.servicenow.com/index.php?title=Import_Set_API . What will happen there is that your data is going to be loaded into an intermediary table. You can then build a transform map out. For the most part the transform map will be a 1:1 relationship from your import table to your destination table, however in the comments, you can use a script to invoke setJournalEntry() as I suggested above. As a side note I'd suggest you use the RESET API explorer, it'll help you build everything out the first time.
-tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2015 04:04 AM
This works as a PUT
url: api/now/v1/table/incident/{sys_id}
body: { "comments": "test update comment" }
The update will show in the activities.