Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

[Solved] Adding comments and work notes via JSONv2

robinm
Kilo Explorer

Hi,

 

Solution posted at the end.

 

Apologies for the length of this; I want to be thorough in what I've tried.

 

I'm struggling to INSERT comments and work notes for incidents via JSONv2. The user account I am using for this is the creator of the incident and can edit comments and work notes through the web interface without issue.

 

The following works for a JSONv2 GET request to query for an incident:

Uri Format: https://instancename.service-now.com/incident.do?JSONv2&sysparm_query=number=INC1234567

(it also works when using sys_id=580b112cf95a6500cf462e82aa6dfe1b )

It returns data for the incident to my script, and is visible in a web browser.

 

I have successfully updated the following fields using a JSONv2 POST request:

  • u_alternate_contact
  • u_machine_name

Uri Format: https://instancename.service-now.com/incident.do?JSONv2&sysparm_query=number=INC1234567&sysparm_acti...

Example JSON: { "u_alternate_contact": "Contact pushed via PowerShell" }

 

Using the above Uri format however, adding comments/work notes doesn't work.

 

After some reading around on other threads it seemed I should be adding these to sys_journal_field, performing the match on this table by using sys_id from the incident in incident.do, and using that for element_id. Testing this via a JSON GET request:

Uri Format: https://instancename.service-now.com/sys_journal_field.do?JSONv2&sysparm_query=element_id=580b112cf9...

... returned all existing work notes and comments for the incident via both the web UI and within my script. The comments/work notes that I tried to POST to incident.do were not visible either in the incident.do table or this. The only comments / work notes visible are those added via the web interface, so I suspect the POST to incident.do is definitely not working.

 

Minor success:

Attempting to update sys_journal_field.do:

Uri Format: https://instancename.service-now.com/sys_journal_field.do?JSONv2&sysparm_action=update&sysparm_query...

JSON:

{

      "element": "work_notes"

      "name": "task"

      "value": "This is a work note added via PowerShell"

}

Rather than INSERT a record, this UPDATED every result (2 x work note, 1 x comment) to become a work note with the value "This is a work note added via PowerShell".

 

I tried sysparm_action=insert instead, but this didn't change anything.

 

At the moment the only thing I can think to do (somehow) is retrieve the existing values for comments and work notes in JSON format, append a new one, and then sysparm_action=update / POST the whole thing back. This is far from ideal however.

 

Help much appreciated!

 

Regards,

 

Robin

 

Solution to insert a new work note:

I had to use INSERT to sys_journal_field.do table as mentioned above, but using the sysparm_query=element_id=xxxxxxxxxxxxx is not required.

However, element_id must be specified in the JSON object, and this is the incident's sys_id value.

Uri Format: https://instancename.service-now.com/sys_journal_field.do?JSONv2&sysparm_action=insert

JSON:

{

      "element": "work_notes"

      "element_id": "580b112cf95a6500cf462e82aa6dfe1b"

      "name": "task"

      "value": "This is a work note added via PowerShell"

}

To insert a comment it would be "element": "comments"

14 REPLIES 14

robinm
Kilo Explorer

Does anyone know the likelihood of getting an answer from the Service Now staff on here? Should I raise an official support case?


karlbarek
Giga Contributor

I was wondering if you made any progress with this issue?   We are running into the same issue, but we are creating our comments via our native iOS/Android app. I made the following post - Comments are not being displayed in Web Portal


Are you just trying to update an individual record? Does this work?



URL:


https://instancename.service-now.com/incident.do?JSONv2&sysparm_query=number=INC12345&sysparm_action...



JSON:


{"work_notes":"This is a work note added via PowerShell"}


Hi Erik,


Thanks for your reply. I'd already tried what you suggest (I quote: "Using the above Uri format however, adding comments/work notes doesn't work.").


Regards,


Robin