ServiceNow Perl API examples

This page provides examples for use of the ServiceNow Perl API.

Creating an Incident

 #!/usr/bin/perl -w

use ServiceNow;
use ServiceNow::Configuration;

my $CONFIG = ServiceNow::Configuration->new();

$CONFIG->setSoapEndPoint("https://demoi1.service-now.com/");
$CONFIG->setUserName("admin");
$CONFIG->setUserPassword("admin");

my $SN = ServiceNow->new($CONFIG);

my $number = $SN->createIncident({"short_description" => "this incident was created from the Perl API", "category" => "hardware"});

print $number ."\n";

Querying an Incident

#!/usr/bin/perl -w

use ServiceNow;
use ServiceNow::Configuration;

my $CONFIG = ServiceNow::Configuration->new();

$CONFIG->setSoapEndPoint("https://demoi1.service-now.com/");
$CONFIG->setUserName("admin");
$CONFIG->setUserPassword("admin");

my $SN = ServiceNow->new($CONFIG);

my @incidents = $SN->queryIncident({'number' => 'INC00002'});
my $count = scalar(@incidents);
print "number of incidents=" . $count . "\n";
foreach my $incident (@incidents) {
    print "Incident number: $incident->{'number'}\n";
    print "Assignent Group: $incident->{'assignment_group'}\n";
    print "Opened by:       $incident->{'opened_by'}\n";
    print "Opened by DV:    $incident->{'dv_opened_by'}\n";
    print "SD:       $incident->{'short_description'}\n";
    print "TW:       $incident->{'time_worked'}\n";
    print "\n"
}

Querying Journal fields

#!/usr/bin/perl -w

use ServiceNow;
use ServiceNow::Configuration;

my $CONFIG = ServiceNow::Configuration->new();

$CONFIG->setSoapEndPoint("https://demoi1.service-now.com/");
$CONFIG->setUserName("admin");
$CONFIG->setUserPassword("admin");

my $SN = ServiceNow->new($CONFIG);

my @journals = $SN->queryJournal('INC00002');

print $journals[0]->{'element'} . " = " . $journals[0]->{'value'} ."\n";
print $journals[1]->{'element'} . " = " . $journals[1]->{'value'} ."\n";