JSON Only working on Incident table?

jrarseneau
Kilo Explorer

Hey all,

I am following the documentation located here: http://wiki.servicenow.com/index.php?title=JSON_Web_Service and running into some unexpected issues.

First, if I use the specific examples listed in the wiki article, I can get a JSON return:
http://instance.service-now.com/incident.do?JSON&sysparm_action=getKeys
http://instance.service-now.com/incident.do?JSON&sysparm_action=get&sysparm_sys_id=31ff3dd41de0f4407...

Both of these return the expected results.. all is good! However, I noticed most examples on the ServiceNow wiki use the incident table. We are trying to retrieve the JSON record for a KB article..

Here's what WORKS:
http://instance.service-now.com/kb_knowledge.do?JSON&sysparm_action=getKeys

This returns a list of sys_id's .. good so far. Here's where it balks:
http://instance.service-now.com/kb_knowledge.do?JSON&sysparm_action=get&sysparm_sys_id=0f7f56da7482d...

This returns absolutely nothing. Just blank. Using JSON, WSDL, ODBC, it always returns blank. Working with the incident table always works, but we can't seem to retrieve any records for the knowledge. I've also tried using kb_view.do but to no avail.

Any tips - do I need to enable something on the knowledge table to get this to work or are we just doing something wrong? I am following the exact documentation on the wiki so I'm thinking it should work - unless the documentation is incomplete.

Thanks!

4 REPLIES 4

afdafd
Kilo Contributor

Hi
I have used the JSON processor alot and i have used it on a quite a few tables without an issue. So i went and tried it on kb_knowledge and got nothing in return.

I took a look at my error and warning log (under system logs ---> warnings) and i saw a error in the JSON processor script include.
Here is the error:
org.mozilla.javascript.EcmaError: Cannot find default value for object.
Caused by error in Script Include: 'JSONProcessor' at line 393

390: if ((ed.isReference() || ed.isChoiceTable()) && this.displayValue == "true")
391: glideRecord[name] = record.getElement(name).getDisplayValue() + '';
392: else
==> 393: glideRecord[name] = record.getElement(name) + '';
394:
395: }
396: if (this.displayVariables == "true")


Did you get the same error in your logs?

I used an admin userid and did a generic pull on the entire knowledge table (by default it only returns 250 rows of data) https://instance.service-now.com/kb_knowledge.do?JSON
I get the same error if i do
https://instance.service-now.com/kb_knowledge.do?JSON&sysparm_query=sys_id=f5d63aef151c9000f19b0ce79247e59a
But all is well when i do
https://instance.service-now.com/incident.do?JSON&sysparm_query=sys_id=0083623269f0b8c45208bae86fc741cd

Adrienne


Adrienne,
Have you tried updating a field in the Incident via JSON?

I am able to retrieve incident info successfully with this,
https://instance.service-now.com/incident.do?JSON&sysparm_action=getRecords&sysparm_query=active=true^number=INC002014173

but I am not able to update.
Could you please share your idea on how to update if you did before?

thanks,
-james


afdafd
Kilo Contributor

Hi James
Yes, i have updated many tables with the JSON Api including incident. you just have to post to the URL you want to update (make sure to use a unique identifier in the URL string or else you will update every single incident that matches your query). Make sure what you post is in XML format

here is an example
{"short_description":"updated by perl", "priority": "3", "impact":"1"}
Post this to your URL https://instance_name.service-now.com/incident.do?JSON&sysparm_query=number=INC002014173

If you are looking for a code example,
From perl, i would use LWP and after i set my userid and password, i would post like this.. where tempurl is the URL above. and $string is the JSON string

my $post_result = $ua->request(POST $tmpurl,
Content_Type => "application/json",
Content => ($string)
);

The above, would set for incident INC002014173 the short desc to be updated by perl, the priority to be 3, and the impact to be 1.

Make sense?
If you need more context, i posted here more questions on perl API... a post with how to use perl to connect to your instance, and pull data. You would just add those few lines above towards the end of the program, and change the url to be a the URL above. Also, you can comment out the GET since you arent pulling info.

Adrienne


Adrienne,
Thanks a lot for your help.
-james