How to retrieve comments for an incident via the rest api

jsamm
Giga Contributor

When using the rest api for incidents, the "comments" journal field always returns an empty string.   Setting "sysparm_display_value = true" will output all of the comments in a single string which is not very useful.   How do I query the journal table for the comments as separate json objects?

1 ACCEPTED SOLUTION

ChrisBurks
Giga Sage

Use the rest api for the sys_journal_field table in the same manner you would query the incident table providing the desired criteria. In this case you're looking for the "comments" from an incident record. So you would set the endpoint to point to the sys_journal_field and provide the incident sys_id that you're looking to gather the comments from as well as set to limit the query to the comments field (because you can gather the work_notes as well if desired)



{your instance name}.service-now.com/api/now/table/sys_journal_field?sysparm_query=element=comments^element_id={your incident sys_id   goes here}


That should give you a result of the comments from a specific incident each as a separate item.



Table API - ServiceNow Wiki


View solution in original post

5 REPLIES 5

ChrisBurks
Giga Sage

Use the rest api for the sys_journal_field table in the same manner you would query the incident table providing the desired criteria. In this case you're looking for the "comments" from an incident record. So you would set the endpoint to point to the sys_journal_field and provide the incident sys_id that you're looking to gather the comments from as well as set to limit the query to the comments field (because you can gather the work_notes as well if desired)



{your instance name}.service-now.com/api/now/table/sys_journal_field?sysparm_query=element=comments^element_id={your incident sys_id   goes here}


That should give you a result of the comments from a specific incident each as a separate item.



Table API - ServiceNow Wiki


jsamm
Giga Contributor

One note, we had to expose the journal table to the rest api, it wasn't allowed by default.


Community Alums
Not applicable

Jesse,



How did you expose the table?



Thanks,


Bruno


Please elaborate on how you exposed it?