Posting a comment with the REST api and getting the ID deterministically

JordanUnito
Tera Contributor

Hey folks, 

 

I've seen a similar question here, but the answers aren't quite getting at what I need, so I thought it'd be appropriate to ask for a different use-case.

 

I'm working on an integration where users can sync data between ServiceNow and an external tool of their choice, and I'm currently in the process of adding the ability to sync comments between tools. For this, I need two main things: A), the ability to actually post comments/work_notes through the API if a given table has them, and B) I need to reliably be able to find exactly the comment that my integration just posted, so that I know it was successfully posted and don't potentially create duplicates (because I'd know the comment I just posted is my own, instead of a user-posted comment I need to sync back to the other tool).

 

Currently I'm using the sys_journal_field table to get a list of comments on the SN side, but because of this issue, I'm aware that posting new comments directly to the sys_journal_field table seems to not work. It does successfully post to that table when I try, but the resulting comments just don't show up in the SN UI. It would be a perfect solution if that worked, though, because it does give me back the comment I just posted - which is ultimately the goal.

 

In lieu of that, it seems like the only thing I can do to post comments is make a patch request on a particular table item (let's say incidents), and then query the sys_journal_field table and... hope? Basically any method of trying to find that comment isn't 100% guaranteed. I could sort by sys_created_on, and take the most recent comment - but that breaks if someone happens to have made a comment at the same time on the same issue. It's an edge case, but it's one that could be common on high-volume tables. Additionally, trying to filter based on the comment of the string, I think, doesn't make sense, because it seems that in certain cases, SN mutates the posted strings slightly, making direct comparison of input and output unreliable.

 

In any case, all of this seems like a lot of work - in just about every other tool I've worked with, when you post a comment through the API, you simply get an ID back for that comment, and that removes all ambiguity. Is there no way to do that through ServiceNow's API?

 

Thanks in advance!

4 REPLIES 4

SanjivMeher
Kilo Patron
Kilo Patron

I know it is possible to both post and retrieve comments. For posting, you can make a api call directly to incident table and to retrieve you can do a get command to sys_journal_field table.

I didn't try myself but below thread should help.

https://timdietrich.me/blog/servicenow-table-api-comments-work-notes/

 


Please mark this response as correct or helpful if it assisted you with your question.

Kieran Anson
Kilo Patron

Hi,

I've never come across this issue, however I don't generally use the Table API for integrations due to the lack of 'protection' it provides us when third party tools go rogue. Much prefer either a scripted rest api or import set.

 

However, testing the steps in When a POST is issued on the work note of a task, the journal data is created but not displayed in t... to reproduce the issue, I wasn't able to. PUT/PATCH on an existing record successfully adds work notes

Hey Kieran - thanks for the answer. 

 

So it looks like reading the issue I linked more closely, it's actually not the problem. I agree with you - I can't repro it either. I read too quickly - my issue happens when I POST directly to the sys_journal_fields table. 

 

Essentially my issue is:

- Find the sys_id of an incident you want to post a comment to

- Use that sys_id as the element_id in a POST to the sys_journal_fields table with all of the other appropriate fields filled out

- Doing a GET on that incident from the incident table now shows that the comment successfully did post in the work_notes section - you can see it through the API.

- However, that comment does not show up in the UI itself. 

 

I get the sense from this that posting directly to the sys_journal_fields table isn't the way to go, but it's just about the only reliable way I can think of to get the ID of the comment I've just posted. Does that make more sense now?

Hi, you can help me? contact me on Internet dedicado monterrey