Creating comments on an Incident via the REST API

bscharm
Kilo Explorer

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.

1 ACCEPTED SOLUTION

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.


View solution in original post

11 REPLIES 11

manikorada
ServiceNow Employee
ServiceNow Employee

Brad,



You can check the following link Getting Started with REST - ServiceNow Wiki this gives the documentation on how to add comments


Mani,



Thanks for the reply. I saw this page, but inserting comments on a POST to /incident table this way does not populate the comments field, it is still empty after the POST. Even in that documentation, you can see in the response after the POST that it did not take the comment in their example! Not sure if this is a bug or if this is the wrong way of doing it.


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.


Andrew,



Thanks for bringing this to my attention. I should have read more carefully to see that reference data is only returned when this is set to true. Makes perfect sense, and now I am able to get comments back. Appreciate the reply!



-Brad