[Solved] Adding comments and work notes via JSONv2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2014 06:55 AM
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2014 06:12 AM
Hi Karl. Unfortunately I haven't made any progress before my original post (although I haven't tried since).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2014 09:49 AM
I have solved this (I think) and will try and post in complete tomorrow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2014 08:21 AM
So, we figured our issue anyways. This is the code for Android:
request.addProperty("name", "task");
request.addProperty("element", "comments");
When we add those fields into our SOAP call, the comments are displayed properly in the Web Portal that are created via the mobile app.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2014 09:09 AM
Aha, funny that didn't work for me, but glad you got it sorted. I have to explicitly pass element_id in the JSON object, with the value of the incident's sys_id. Will add this to the original post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2014 09:20 AM
We have to do that as well. However, we aren't calling the JSONv2 feature you are using.
So, the entire SOAP request object (using ksoap library for Android):
SoapObject request = new SoapObject(NAMESPACE1, METHOD_NAME1);
request.addProperty("element_id", incidentSysid);
request.addProperty("value", commentValue);
request.addProperty("name", "task");
request.addProperty("element", "comments");