Perl API Incident

An object representation of an incident in the ServiceNow platform. Provides subroutines for querying, updating, and creating incidents.

Incident module

ServiceNow Perl API - Incident perl module

Creating an Incident

#!/usr/bin/perl -w

use ServiceNow;
use ServiceNow::Configuration;
use ServiceNow::ITIL::Incident;

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

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

# setting incident values as a hash map in the insert argument
my $incident = ServiceNow::ITIL::Incident->new($CONFIG);
my $sys_id = $incident->insert({"short_description" => "this incident was created from the Perl API", "category" => "hardware"});
print $sys_id ."\n";

# setting incident values by making setValue calls to the incident object
$incident = ServiceNow::ITIL::Incident->new($CONFIG);
$incident->setValue("short_description", "this incident was created from the Perl API - 2");
$incident->setValue("category", "hardware");
$sys_id = $incident->insert();
print $sys_id ."\n";

Querying for Incidents

#!/usr/bin/perl -w

use ServiceNow;
use ServiceNow::Configuration;
use ServiceNow::ITIL::Incident;

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

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

my $incident = ServiceNow::ITIL::Incident->new($CONFIG);
$incident->addQuery("assignment_group", "Service Desk");
$incident->addQuery("category", "Hardware");
$incident->query();
while($incident->next()) {
        print "number=" . $incident->getValue("number") . "\n";
        print "sd=" . $incident->getValue("short_description") . "\n";
        print "opened_by Display Value= " . $incident->getDisplayValue("opened_by") . "\n";
        print "opened_by sys_id= " . $incident->getValue('opened_by');
}

Adding an attachment to a newly created Incident

#!/usr/bin/perl -w

use ServiceNow;
use ServiceNow::Configuration;
use ServiceNow::ITIL::Incident;

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

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


my $incident = ServiceNow::ITIL::Incident->new($CONFIG);
$incident->setValue("short_description", "test incident for attachment 2");
$incident->insert();
$incident->attach("/Users/davidloo/Desktop/test_files/number_test.xls");

Constructor

new

new(Configuration);

Example:
$incident = ServiceNow::ITIL::Incident->new($CONFIG);

Takes a configuration object and manufactures an Incident object connected to the ServiceNow instance.

Subroutines inherited from Task.pm

  • attach
  • close
  • create
  • queryJournal
  • reassign
  • reopen

Subroutines inherited from GlideRecord.pm

  • addQuery
  • getValue
  • getDisplayValue
  • setValue
  • next
  • insert
  • query
  • update

Subroutines

close

close(number, hashmap);

Example:
$incident->close($number)

Close an incident and update values described in the hash map passed in.

reopen

reopen(number, hashmap);

Example:
$incident->reopen($number);

Re-open a closed incident and update values described in the hash map passed in.

createProblem

createProblem();

Create a problem ticket from an incident and associate it. Returns the sys_id of the newly created problem ticket

createChange

createChange();

Create a change request from an incident and associate it. Returns the sys_id of the newly created change request