adding journal entries to an incident using web api
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2012 08:43 PM
I am trying to use the JSON web API to create incidents in SN and using perl at the moment but I don't think that is relevant to the problem I have.
I can create the incident with out problems and can retrieve it again or look at it from the web interface. What I can't figure out is how to attach journal entries to the incident.
my $result = $self->json_table('incident', '', undef, 'insert', qq|{"short_description":"$short" $category $group, "u_requestor": "$user"}| );
my $number = $result->{'records'}->[0]->{'number'};
pr_object($result->{records}->[0] );
$data = ref $data eq 'ARRAY' ? join("\n", @$data) : $data if defined $data;
$result = $self->json_table('sys_journal_field', 'number', $number, 'update', qq|{"element": "comments" "value" : "$data" }| );
The question is what search clause should I use to link the journal to the incident. I.e. the second and third parameters of the json_table call.
This code does not generate any errors but the journal entries just disappear. I can find them by searching but can't figure out what they are attached to.
Russell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2012 08:20 AM
You can test out the queries on your browser's address bar.
The following URL gives me all journal entries to an incident with sys_id: d77f725ac3bb2000fb47df384aba8fa4
Here is the URL:
https://MYINSTANCE.service-now.com/sys_journal_field_list.do?JSON&sysparm_action=getRecords&sysparm_query=element_id=d77f725ac3bb2000fb47df384aba8fa4
The URL is broken down in the following parameters:
sysparm_action : getRecords
This tells the JSON to get full records that match a query
sysparm_query : element_id=d77f725ac3bb2000fb47df384aba8fa4
This parameter is the one that contains the encoded query. The encoded query I used is "element_id=" with the sys_id on the right hand side of the equals sign.
Just plug the proper sys_id value into the element_id portion of the query. Your Perl script should be able to return this information.
Here is the response I got:
{
"records":[
{
"element":"comments",
"element_id":"d77f725ac3bb2000fb47df384aba8fa4",
"name":"task",
"sys_created_by":"admin",
"sys_created_on":"2012-09-11 15:09:00",
"sys_id":"3220c3d3c3543000fb47df384aba8f86",
"value":"My Comment #1"
},
{
"element":"work_notes",
"element_id":"d77f725ac3bb2000fb47df384aba8fa4",
"name":"task",
"sys_created_by":"admin",
"sys_created_on":"2012-09-11 15:09:00",
"sys_id":"7a20c3d3c3543000fb47df384aba8f86",
"value":"My Worknote #1"
},
{
"element":"comments",
"element_id":"d77f725ac3bb2000fb47df384aba8fa4",
"name":"task",
"sys_created_by":"admin",
"sys_created_on":"2012-09-11 15:09:08",
"sys_id":"a8304757c3943000fb47df384aba8f10",
"value":"My Comment #2"
},
{
"element":"work_notes",
"element_id":"d77f725ac3bb2000fb47df384aba8fa4",
"name":"task",
"sys_created_by":"admin",
"sys_created_on":"2012-09-11 15:09:17",
"sys_id":"f2304757c3943000fb47df384aba8f56",
"value":"My Worknote #2"
}
]
}
Sorry I don't have Perl code for this, but hopefully these parameters give you some guidance needed to know what to plug into your Perl script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2012 05:03 PM
Thanks very much John -- I thought I had tried linking event_id in the journal to sys_id in the incident but may be I did not. Will have another try just as soon as I can get the authentication working again.
I had that all set up but the server got refreshed and now I can't seem to get the account set up properly. Whatever I try I get back a return code of 200 and and empty html document.
I have the JSON web api plugin enabled -- is there anything else I need?
I *can* get the urls to work in the browser once I have logged in via shibboleth but when I try from perl (either using the perl API or the JSON web api) all I get back is the empty html doc -- no matter what creds I use. I.e. supposedly valid cred give the same result as definitely invalid ones.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2012 08:13 AM
JSON web api plugin should be all you need. When going through the browser with the JSON parameter, it should bypass shibboleth and use basic authentication (a small popup window for username and password). You would need to specify a local username and password for a ServiceNow user that has rights to view that table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2012 04:25 PM
Thanks again John.
The shibboleth bypass is not working which would explain why I am having problems.
When I use a 'new' (i.e. one with no shib sessions open) browser and go to http://askit.sandpit.auckland.ac.nz/servicenow/sys_user.do?JSON&sysparm_query=active=true^user_name=rful011
I get the the SSO login page.
The one person who really understands the shibb setup for SN here is currently in the US but will be back next week and I'll leave it until he gets back. He had me properly set up before he left but the box got 'refreshed'.
Thanks again for your help.