Using ServiceNow PERL API to access cmdb_ci_outage table

icalderus
Kilo Contributor

Hello All!

Second post here, thanks in advance for the help.

I had previously written the forums asking for help with querying the cmdb_ci_outage table , piping those results to a flat file. I was able to do so successfully using the ServiceNow ODBC on windows xp. However, things have changed.

The scope of the project is now such that Windows is being tossed out altogether, and I have been asked to use the Service Now Perl API to accomplish the same thing, that is , access the cmdb_ci_outage table and pipe the output into a flat file.

As such I must say I am completely new to the Perl API. From what I gather there are some functions that can get incident info, enter incident info, etc. However my need is to specifically query the cmdb_ci_outage table using the Perl API.

Does ANYONE have any ideas or sample clues/code that may help? I must add I havent touched Perl in quite some time, however I am fairly decent with ksh code so I gather I can suffice.

thanks guys!

17 REPLIES 17

icalderus
Kilo Contributor

Thank you for that correction. Since I am new to Service Now the functions of the software in addition to the navigation are both new to me, as such your input is invaluable.

Having said that , what is the path to the Form View and Section Heading? In this way I can create a view using the Personalized Form Layout menu option.

This is all french to me at the moment, anything you can offer is much much much appreciated.


Again, big picture is I have a SQL query/join that I need to run in order to pipe the output to nagios for scheduled downtimes.

Thus far I have looked into the PERL API and made some progress retrieving values from the cmdb_ci_outage table, but nowhere near where I need to be in terms of the formatted output that is desired.

Thanks!!!


See this wiki article: http://wiki.servicenow.com/index.php?title=Personalizing_Forms


icalderus
Kilo Contributor

Thanks again Scott,

However this is all very confusing to me. I am to create a new "Form" but based off what page? What is the navigation to even get to a form? All I wanted to do was create a view of some sort that can produce output from 3 different tables. This output would then be piped into our nagios system to setup scheduled downtime windows.

I have a 3 table SQL join statement.

How do I create a form that would incorporate this type of SQL join?

Looking at the tutorial I can see that I can pick and choose fields from a particular table however, how would I do so with 3 different tables?
The 3 tables are :

cmdb_ci_outage
change_request
change_task

How would I create 1 form that would incorporate all of the required fields from each one of these tables into 1 statement? From what I understand if I can simply create this custom form then I can run queries against this view/form and get the info I need correct ( I hope ) ?

This seems a bit confusing and not too straightforward to me at the moment.

Is there any way to speak on the phone about this? Perhaps that would help to clear out my ignorance on this issue. Again, thanks for your patience in advance, I truly appreciate it.


It's possible you'll need a database view to get what you need. http://wiki.servicenow.com/index.php?title=Database_Views

I would recommend engaging with ServiceNow support on this. I'm just another ServiceNow user who happens to have been down this path before. 🙂


icalderus
Kilo Contributor

Thanks Scott,

I appreciate it, Service Now is asking me to define a custom view and query that view on the backend.

As of now I dont have system admin rights to even create a view in Service Now, so I am waiting on that.

However I was able to rummage some PERL up last night that got me a conditional return on the cmdb_ci_outage table.

Scott, what would be the way to add a AND to this condition? In other words lets say I wanted to get results where sys_created_by='xyz' AND ( a second condition)..

this is what I have now :

#!/usr/bin/perl -w
#use SOAP::Lite ( +trace => all, maptype => {} );
use SOAP::Lite;

sub SOAP::Transport::HTTP::Client::get_basic_credentials {
return 'user' => 'pass';
}

my $soap = SOAP::Lite
-> proxy('https://dev.service-now.com/cmdb_ci_outage.do?SOAP');

my $method = SOAP::Data->name('getRecords')
->attr({xmlns => 'http://www.service-now.com/'});

# get incident by sys_id
my @params = ( SOAP::Data->name(sys_created_by => 'xyz123') );
my %keyHash = %{ $soap->call($method => @params)->body->{'getRecordsResponse'} };

# iterate through all fields and print them
#foreach my $k (keys %keyHash) {
# print "$k=$keyHash{$k}\n";
#}

my $i = 0;
my $size = @{$keyHash{'getRecordsResult'}};
for ($i=0; $i<$size; $i++) {
my %record = %{$keyHash{'getRecordsResult'}[$i]};
print "------------------------------ $i ----------------------------\n";
foreach my $kk (keys %record) {
print "$kk=$record{$kk}\n";
}
}