using perl with servicenow

39
PDF generated using the open source mwlib toolkit. See http://code.pediapress.com/ for more information. PDF generated at: Sun, 16 Mar 2014 17:13:11 PST Using Perl with ServiceNow

Upload: gunalprasadg

Post on 29-Dec-2015

175 views

Category:

Documents


0 download

DESCRIPTION

Using Perl With ServiceNow

TRANSCRIPT

Page 1: Using Perl With ServiceNow

PDF generated using the open source mwlib toolkit. See http://code.pediapress.com/ for more information.PDF generated at: Sun, 16 Mar 2014 17:13:11 PST

Using Perl with ServiceNow

Page 2: Using Perl With ServiceNow

ServiceNow.pm 1

ServiceNow.pm

Perl API

• ServiceNow.pm• ITIL Objects

• Incident.pm• Problem.pm• Change.pm• Request.pm• RequestedItem.pm• SC_Task.pm• Ticket.pm• Task.pm• Approval.pm

• Other

• Configuration.pm• GlideRecord.pm• Attachment.pm

Related Topics

• Integration Overview• Web Services

Get the Book

Get the Book

ServiceNow moduleServiceNow Perl API - ServiceNow perl module

DesciptionServiceNow module is a collection of Perl subroutines that provides convenient and direct access to the ServiceNowplatform

System RequirementsThe ServiceNow Perl API requires Perl 5.8 with the following modules installed• SOAP::Lite (prerequisites http:/ / soaplite. com/ prereqs. html) 0.71 or later• Crypt::SSLeay• IO::Socket::SSL• File::Basename• MIME::Types• MIME::Type• MIME::Base64

Page 3: Using Perl With ServiceNow

ServiceNow.pm 2

Examples

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"

}

Page 4: Using Perl With ServiceNow

ServiceNow.pm 3

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";

Constructor

new

new(Configuration object, optional Instance ID)Example:

$config = ServiceNow::Configuration->new();

$SN = ServiceNow->new($config);

Sets up an instance of the ServiceNow object using a Configuration object and an optional Instance ID.

Subroutines

Incident

createIncident

createIncident(optional paramaters)Example:

$number = $SN->createIncident({"short_description" => "this is the short description"});

Create an incident. Returns an incident number upon success. On failure returns undef.

queryIncident

queryIncident(Reference to named parameters hash of Incident fields and exact values)Example:

@results = $SN->queryIncident({'number' => 'INC0000054'});

Query for Incidents matching specified criteria. Returns an array of incident records.

Page 5: Using Perl With ServiceNow

ServiceNow.pm 4

updateIncident

updateIncident($number, optional hash of Incident fields and values to update)Example:

$ret = $SN->updateIncident($number,{$field => $value});

Update a ServiceNow incident Returns undef on failure, all other values indicate success.

closeIncident

closeIncident(incident number, optional hash of Incident fields and values to update)Example:

$number = $SN->closeIncident($number, {$field => $value});

Close a ServiceNow Incident and optionally update field values. Returns the incident number on success, undef onfailure.

reopenIncident

reopenIncident(incident number)Example:

my $ret = $SN->reopenIncident('INC99999');

Reopen a closed ServiceNow incident. Returns the incident number on success, undef on failure.

reassignIncident

reassignIncident(Incident number, assignment group, optional assigned to)Example:

my $ret = $SN->reassignIncident('INC99999', 'SOME_GROUP');

my $ret = $SN->reassignIncident('INC99999', 'SOME_GROUP', 'username');

Reassign a ServiceNow Incident to a new assignment_group.(and optionally specify an assigned_to) Returns theincident number on success, undef on failure.

Ticket

createTicket

createTicket(Reference to named parameters hash of ticket fields and values)Example:

my $number = $SN->createTicket({"category" => "hardware"});

Create a ServiceNow ticket associated with an incident. Returns a ticket number upon success. On failure returnsundef.

updateTicket

updateTicket(The ticket number , Reference to named parameters hash of ticket fields and values to update)Example:

my $ret = $SN->updateTicket($number, {$field => $value});

Page 6: Using Perl With ServiceNow

ServiceNow.pm 5

Returns undef on failure, all other values indicate success.

queryTicket

queryTicket( Reference to named parameters hash of Incident fields and exact values )Example:

my @tickets = $SN->queryTicket({'number' => $number});

Query for tickets matching specified criteria. Reference to array of hashes of all matching tickets, undef on failure orif no records found.

closeTicket

closeTicket(Ticket number, {$field => $value})Example:

my $ret = $SN->closeTicket($number);

my $ret = $SN->closeTicket($number, {"comments" => "ticket closed"});

Close a ServiceNow ticket and optionally specify work effort. Returns the ticket number on success, undef onfailure.

reopenTicket

reopenTicket(The ticket number)Example:

my $ret = $SN->reopenTicket('TKT99999');

Reopen a closed ServiceNow ticket. Returns the ticket number on success, undef on failure.

reassignTicket

reassignTicket(ticket number, the incident assignment group, optional person to assign the ticket to)Example:

my $ret = $SN->reassignTicket('TKT99999', 'SOME_GROUP');

my $ret = $SN->reassignTicket('TKT99999', 'SOME_GROUP', 'username');

Reassign a ServiceNow ticket to a new assignment_group. Returns the ticket number on success, undef on failure.

RequestedItem / Request

createRequestedItem

createRequestedItem(catalog item number, requested for, variables)Example:my $req = $SN->createRequestedItem('CITM10000', "username", {'description' => 'Some description', 'group' => 'SOME_GROUP'});

Create a Service Catalog RequestedItem (and indirectly the associated Request and Tasks). Returns a RequestedItemnumber upon success. On failure returns undef.

Page 7: Using Perl With ServiceNow

ServiceNow.pm 6

queryRequestedItem

queryRequestedItem(Reference to named parameters hash of RequestedItem fields and exact values)Example:

my $requestedItems = $SN->queryRequestedItem({'number' => 'SOME_RI_NUMBER'});

Query for RequestedItems matching specified criteria. Reference to array of hashes of all matching RequestedItem,undef on failure or if no records found.

queryRequest

queryRequest(Reference to named parameters hash of Request fields and exact values)Example:

my $requests = $SN->queryRequest({'number' => 'SOME_REQUEST_NUMBER'});

Query for Requests matching specified criteria. Reference to array of hashes of all matching Request, undef onfailure or if no records found.

Task

createTask

createTask(optional paramaters)Example:

$number = $SN->createTask({"short_description" => "this is the short description"});

Create a task record. Returns an task number upon success. On failure returns undef.

closeTask

closeTask(task number, optional work effort in seconds)Example:

my $ret = $SN->closeTask($number);

my $ret = $SN->closeTask($number, {$field => $value});

Close a ServiceNow Task and optionally update field values. Returns true on success, undef on failure.

reopenTask

reopenTask(task number)Example:

my $ret = $SN->reopenTask('TASK99999');

Reopen a closed ServiceNow Task. Returns true on success, undef on failure.

reassignTask

reassignTask(task number, assignment group, optional person it is being assigned to)Example:

my $ret = $SN->reassignTask('TASK99999', 'SOME_GROUP');

my $ret = $SN->reassignTask('TASK99999', 'SOME_GROUP', 'username');

Page 8: Using Perl With ServiceNow

ServiceNow.pm 7

Reassign a ServiceNow Task to a new assignment_group. (and optionally specify an assigned_to) Returns true onsuccess, undef on failure.

updateTask

updateTask(task number, reference to named parameters hash of Task fields and values)Example:

my $ret = $SN->updateTask($number, {$field => $value});

Update a ServiceNow Task. Returns true on success, undef on failure.

queryTask

queryTask(reference to named parameters hash of Task fields and exact values )Example:

my @tasks = $SN->queryTask({'number' => $number});

foreach my $task (@tasks) {

print "Incident number: $task->{'number'}\n";

print "Assignent Group: $task->{'assignment_group'}\n";

print "Opened by: $task->{'opened_by'}\n";

print "SD: $task->{'short_description'}\n";

print "TW: $task->{'time_worked'}\n";

print "\n"

}

Query for Tasks matching specified criteria. Array of hashes of all matching Tasks, undef on failure or if no recordsfound.

Journal

queryJournal

queryJournal(Incident/Ticket/Task number, optional journal field name )Query for journals entries for the specified incident, ticket or task. Return array of hashes of all matching Journals,undef on failure or if no records found. There will be one hash per per journal entry, 'value' will contain the journalentry string, 'element' will be the name of the field (e.g. 'comments', 'work_notes', etc.)

appendJournal

appendJournal(Incident/Ticket/Task number, field name, journal text)Example:

my $ret = $SN->appendJournal('INC99999', 'comments' "some comment text");

Append a journal entry to the specified journal field of an incident, ticket, or task. Returns true on success, undef onfailure.

Page 9: Using Perl With ServiceNow

ServiceNow.pm 8

Approval

queryApproval

queryApproval(reference to named parameters hash of approval fields and exact values)Example:

my @approvals = $SN->queryApproval({'approver' => 'username'});

Query for approvals Return array of hashes of all matching approvals, undef on failure or if no records found.

approve

approve(sys_id of the approval,approval state,optional comment text)Example:

my $ret = $SN->approve($sys_id, 'Approved');

my $ret = $SN->approve($sys_id, 'Rejected', "Please do something else");

Approve/reject a ServiceNow approval request and optionally provide a comment. Returns the sys_id on success,undef on failure.

Dictionary

queryFields

queryFields(table, optional boolean)Example:

my @fields = $SN->queryFields('incident');

List all the fields of an Incident, Request, RequestedItem or Task. Returns a reference to a hash of fields in thespecified table type. The hash key is the field name, and the hash value is a hash reference to attributes about thefield: 'mandatory', 'hint', 'label', 'reference' and 'choice'. Returns undef on failure. If getchoices is true then 'choices' isa reference to a hash containing individual choices, keyed by choice value and containing choice 'label' and 'hint'.

Page 10: Using Perl With ServiceNow

9

ITIL Objects

Incident.pm

Perl API

• ServiceNow.pm• ITIL Objects

• Incident.pm• Problem.pm• Change.pm• Request.pm• RequestedItem.pm• SC_Task.pm• Ticket.pm• Task.pm• Approval.pm

• Other

• Configuration.pm• GlideRecord.pm• Attachment.pm

Related Topics

• Integration Overview• Web Services

Get the Book

Get the Book

Incident moduleServiceNow Perl API - Incident perl module

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

System RequirementsThe ServiceNow Perl API requires Perl 5.8 with the following modules installed• SOAP::Lite (prerequisites http:/ / soaplite. com/ prereqs. html) 0.71 or later• Crypt::SSLeay• IO::Socket::SSL

Page 11: Using Perl With ServiceNow

Incident.pm 10

Examples

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";

Page 12: Using Perl With ServiceNow

Incident.pm 11

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

newnew(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

Page 13: Using Perl With ServiceNow

Incident.pm 12

Subroutines inherited from GlideRecord.pm• addQuery• getValue• getDisplayValue• setValue• next• insert• query• update

Subroutines

closeclose(number, hashmap);Example:

$incident->close($number)

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

reopenreopen(number, hashmap);Example:

$incident->reopen($number);

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

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

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

Page 14: Using Perl With ServiceNow

Problem.pm 13

Problem.pm

Perl API

• ServiceNow.pm• ITIL Objects

• Incident.pm• Problem.pm• Change.pm• Request.pm• RequestedItem.pm• SC_Task.pm• Ticket.pm• Task.pm• Approval.pm

• Other

• Configuration.pm• GlideRecord.pm• Attachment.pm

Related Topics

• Integration Overview• Web Services

Get the Book

Get the Book

Problem moduleServiceNow Perl API - Problem perl module

DesciptionAn object representation of a Problem in the ServiceNow platform. Provides subroutines for querying, updating, andcreating problems.

System RequirementsThe ServiceNow Perl API requires Perl 5.8 with the following modules installed• SOAP::Lite (prerequisites http:/ / soaplite. com/ prereqs. html) 0.71 or later• Crypt::SSLeay• IO::Socket::SSL

Page 15: Using Perl With ServiceNow

Problem.pm 14

Constructor

newnew(Configuration);Example:

$problem = ServiceNow::ITIL::Problem->new($CONFIG);

Takes a configuration object and manufactures a Problem 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

Page 16: Using Perl With ServiceNow

Change.pm 15

Change.pm

Perl API

• ServiceNow.pm• ITIL Objects

• Incident.pm• Problem.pm• Change.pm• Request.pm• RequestedItem.pm• SC_Task.pm• Ticket.pm• Task.pm• Approval.pm

• Other

• Configuration.pm• GlideRecord.pm• Attachment.pm

Related Topics

• Integration Overview• Web Services

Get the Book

Get the Book

Change moduleServiceNow Perl API - Change perl module

DesciptionAn object representation of an Change in the ServiceNow platform. Provides subroutines for querying, updating, andcreating change requests.

System RequirementsThe ServiceNow Perl API requires Perl 5.8 with the following modules installed• SOAP::Lite (prerequisites http:/ / soaplite. com/ prereqs. html) 0.71 or later• Crypt::SSLeay• IO::Socket::SSL

Page 17: Using Perl With ServiceNow

Change.pm 16

Constructor

newnew(Configuration);Example:

$change = ServiceNow::ITIL::Change->new($CONFIG);

Takes a configuration object and manufactures an Change 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

Page 18: Using Perl With ServiceNow

Request.pm 17

Request.pm

Perl API

• ServiceNow.pm• ITIL Objects

• Incident.pm• Problem.pm• Change.pm• Request.pm• RequestedItem.pm• SC_Task.pm• Ticket.pm• Task.pm• Approval.pm

• Other

• Configuration.pm• GlideRecord.pm• Attachment.pm

Related Topics

• Integration Overview• Web Services

Get the Book

Get the Book

Request moduleServiceNow Perl API - Request perl module

DesciptionAn object representation of an Request in the ServiceNow platform. Provides subroutines for querying, updating,and creating service catalog requests.

System RequirementsThe ServiceNow Perl API requires Perl 5.8 with the following modules installed• SOAP::Lite (prerequisites http:/ / soaplite. com/ prereqs. html) 0.71 or later• Crypt::SSLeay• IO::Socket::SSL

Page 19: Using Perl With ServiceNow

Request.pm 18

Constructor

newnew(Configuration);Example:

$request = ServiceNow::ITIL::Request->new($CONFIG);

Takes a configuration object and manufactures an Request 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

createRequestcreateRequest(user);Create a service request for the specified user

Page 20: Using Perl With ServiceNow

RequestedItem.pm 19

RequestedItem.pm

Perl API

• ServiceNow.pm• ITIL Objects

• Incident.pm• Problem.pm• Change.pm• Request.pm• RequestedItem.pm• SC_Task.pm• Ticket.pm• Task.pm• Approval.pm

• Other

• Configuration.pm• GlideRecord.pm• Attachment.pm

Related Topics

• Integration Overview• Web Services

Get the Book

Get the Book

RequestedItem moduleServiceNow Perl API - RequestedItem perl module

DesciptionAn object representation of an Requested Item in the ServiceNow platform. Provides subroutines for querying,updating, and creating service catalog requested item.

System RequirementsThe ServiceNow Perl API requires Perl 5.8 with the following modules installed• SOAP::Lite (prerequisites http:/ / soaplite. com/ prereqs. html) 0.71 or later• Crypt::SSLeay• IO::Socket::SSL

Page 21: Using Perl With ServiceNow

RequestedItem.pm 20

Constructor

newnew(Configuration);Example:

$req_item = ServiceNow::ITIL::RequestedItem->new($CONFIG);

Takes a configuration object and manufactures an Requested Item 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

Page 22: Using Perl With ServiceNow

SC_Task.pm 21

SC_Task.pm

Perl API

• ServiceNow.pm• ITIL Objects

• Incident.pm• Problem.pm• Change.pm• Request.pm• RequestedItem.pm• SC_Task.pm• Ticket.pm• Task.pm• Approval.pm

• Other

• Configuration.pm• GlideRecord.pm• Attachment.pm

Related Topics

• Integration Overview• Web Services

Get the Book

Get the Book

SC_Task moduleServiceNow Perl API - SC_Task perl module

DesciptionAn object representation of an Service Request Task in the ServiceNow platform. Provides subroutines for querying,updating, and creating sc_task.

System RequirementsThe ServiceNow Perl API requires Perl 5.8 with the following modules installed• SOAP::Lite (prerequisites http:/ / soaplite. com/ prereqs. html) 0.71 or later• Crypt::SSLeay• IO::Socket::SSL

Page 23: Using Perl With ServiceNow

SC_Task.pm 22

Constructor

newnew(Configuration);Example:

$sc_task = ServiceNow::ITIL::RequestedItem->new($CONFIG);

Takes a configuration object and manufactures an Service Catalog Task 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

Page 24: Using Perl With ServiceNow

Ticket.pm 23

Ticket.pm

Perl API

• ServiceNow.pm• ITIL Objects

• Incident.pm• Problem.pm• Change.pm• Request.pm• RequestedItem.pm• SC_Task.pm• Ticket.pm• Task.pm• Approval.pm

• Other

• Configuration.pm• GlideRecord.pm• Attachment.pm

Related Topics

• Integration Overview• Web Services

Get the Book

Get the Book

Ticket moduleServiceNow Perl API - Ticket perl module

DesciptionAn object representation of a Ticket in the ServiceNow platform. Provides subroutines for querying, updating, andcreating tickets.

System RequirementsThe ServiceNow Perl API requires Perl 5.8 with the following modules installed• SOAP::Lite (prerequisites http:/ / soaplite. com/ prereqs. html) 0.71 or later• Crypt::SSLeay• IO::Socket::SSL

Page 25: Using Perl With ServiceNow

Ticket.pm 24

Constructor

newnew(Configuration);Example:

$ticket = ServiceNow::ITIL::Ticket->new($CONFIG);

Takes a configuration object and manufactures an Ticket 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

Page 26: Using Perl With ServiceNow

Task.pm 25

Task.pm

Perl API

• ServiceNow.pm• ITIL Objects

• Incident.pm• Problem.pm• Change.pm• Request.pm• RequestedItem.pm• SC_Task.pm• Ticket.pm• Task.pm• Approval.pm

• Other

• Configuration.pm• GlideRecord.pm• Attachment.pm

Related Topics

• Integration Overview• Web Services

Get the Book

Get the Book

Task moduleServiceNow Perl API - Task perl module

DesciptionAn object representation of a Task in the ServiceNow platform. Provides subroutines for querying, updating, andcreating tasks. Task is the parent class of Incident, Problem, Change, SC_Task and Ticket. These child classesinherit subroutines from this class.

System RequirementsThe ServiceNow Perl API requires Perl 5.8 with the following modules installed• SOAP::Lite (prerequisites http:/ / soaplite. com/ prereqs. html) 0.71 or later• Crypt::SSLeay• IO::Socket::SSL

Page 27: Using Perl With ServiceNow

Task.pm 26

Constructor

newnew(Configuration);Example:

$task = ServiceNow::ITIL::Task->new($CONFIG);

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

Subroutines inherited from GlideRecord.pm• addQuery• getValue• getDisplayValue• setValue• next• insert• query• update

Subroutines

createcreate(optional paramaters)Example:

$task->create();

Creates and inserts Task/Incident/Ticket/SC_Task record into the respective table. Returns the number of createdrecord on succes, undef on failure.

closeclose(number of record, optional parameters)Example:

$task->close('INC1000312');

Sets the state of Task/Incident/Ticket/SC_Task to closed and updates the respective table. Returns the number ofcreated record on success, undef on failure.

Page 28: Using Perl With ServiceNow

Task.pm 27

reopenreopen(number of record, optional parameters)Example:

$task->reopen('TKT1003010');

Sets the state of Task/Incident/Ticket/SC_Task to open and updates the respective table.

reassignreassign(number, group, user);Example:

$incident->reassign($number, 'Database', 'user')

Re-assign an incident to the group and user specified.

queryJournalqueryJournal(configuration file, optional field name)Example:

$task->queryJournal($config, 'work_notes');

Returns an array of hash references to each journal associated with the current Task/Incident/Ticket/SC_Task.Optional field name refines the search to a specified field.

attachattach(file path)Example:

$task->attach("/Users/davidloo/Desktop/test_files/number_test.xls");

Attach a file to a record of Task

Page 29: Using Perl With ServiceNow

Approval.pm 28

Approval.pm

Perl API

• ServiceNow.pm• ITIL Objects

• Incident.pm• Problem.pm• Change.pm• Request.pm• RequestedItem.pm• SC_Task.pm• Ticket.pm• Task.pm• Approval.pm

• Other

• Configuration.pm• GlideRecord.pm• Attachment.pm

Related Topics

• Integration Overview• Web Services

Get the Book

Get the Book

Approval moduleServiceNow Perl API - Approval perl module

DesciptionAn object representation of an Approval record in the ServiceNow platform. Provides subroutines for querying,updating, and creating approvals.

System RequirementsThe ServiceNow Perl API requires Perl 5.8 with the following modules installed• SOAP::Lite (prerequisites http:/ / soaplite. com/ prereqs. html) 0.71 or later• Crypt::SSLeay• IO::Socket::SSL

Page 30: Using Perl With ServiceNow

Approval.pm 29

Constructor

newnew(Configuration);Example:

$approvals = ServiceNow::ITIL::Approval->new($CONFIG);

Takes a configuration object and manufactures an Approval 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

rejectreject(sys_id of approval record, optional comment string)Example:

$approval->reject($sysID,$comment);

Reject the Approval record with specified sys id, and add comment to approval if given.

approveapprove(sys_id of approval record, optional comment string)Example:

$approval->approve($sysID,$comment);

Approve the Approval record with specified sys id, and add comment to approval if given.

Page 31: Using Perl With ServiceNow

30

Other

Configuration.pm

Perl API

• ServiceNow.pm• ITIL Objects

• Incident.pm• Problem.pm• Change.pm• Request.pm• RequestedItem.pm• SC_Task.pm• Ticket.pm• Task.pm• Approval.pm

• Other

• Configuration.pm• GlideRecord.pm• Attachment.pm

Related Topics

• Integration Overview• Web Services

Get the Book

Get the Book

Configuration moduleServiceNow Perl API - Ticket perl module

DesciptionAn object representation of a Configuration object used to access your ServiceNow instance.

System RequirementsThe ServiceNow Perl API requires Perl 5.8 with the following modules installed• SOAP::Lite (prerequisites http:/ / soaplite. com/ prereqs. html) 0.71 or later• Crypt::SSLeay• IO::Socket::SSL

Page 32: Using Perl With ServiceNow

Configuration.pm 31

Constructor

newnew();Example:

$conf = ServiceNow::Configuration->new();

Create a new Configuration object and start customizing it to be used for other objects

Subroutines

getSoapEndpointgetSoapEndpoint(target_table);Gets the complete SOAP endpoint used to access your ServiceNow instance, given the table name.

setSoapEndPointsetSoapEndPoint(endpoint_url);Sets the complete SOAP endpoint used to access your ServiceNow instance.For example:

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

$CONFIG->setSoapEndPoint("https://instance_name.service-now.com/");

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

getUserNamegetUserName();Get the user name used to authenticate a connection to the SOAP endpoint

setUserNamesetUserName(user_name);Set the user name used to authenticate a connection to the SOAP endpoint

getUserPasswordgetUserPassword();Get the user password used to authenticate a connection to the SOAP endpoint

Page 33: Using Perl With ServiceNow

Configuration.pm 32

setUserPasswordsetUserPassword(user_password);Set the user password used to authenticate a connection to the SOAP endpoint

getConnectiongetConnection(target_table);Get the Connection object used to access the ServiceNow SOAP endpoint

GlideRecord.pm

Perl API

• ServiceNow.pm• ITIL Objects

• Incident.pm• Problem.pm• Change.pm• Request.pm• RequestedItem.pm• SC_Task.pm• Ticket.pm• Task.pm• Approval.pm

• Other

• Configuration.pm• GlideRecord.pm• Attachment.pm

Related Topics

• Integration Overview• Web Services

Get the Book

Get the Book

GlideRecord moduleServiceNow Perl API - GlideRecord perl module

DesciptionAn object representation of a GlideRecord object used to access your ServiceNow instance.

System RequirementsThe ServiceNow Perl API requires Perl 5.8 with the following modules installed• SOAP::Lite (prerequisites http:/ / soaplite. com/ prereqs. html) 0.71 or later• Crypt::SSLeay• IO::Socket::SSL

Page 34: Using Perl With ServiceNow

GlideRecord.pm 33

Constructor

newnew(Configuration object, Table name, optional caller object)

$config = ServiceNow::Configuration->new();

$glideRecord = ServiceNow::GlideRecord->new($config,'incident',$me);

Constructor. Access to the ServiceNow Glide Record object. The caller object is optional unless creating a Class thatinherits GlideRecord (See any class in ServiceNow/ITIL for example).

Subroutines

insertinsert(optional hash argument)Example:

$glideRecord->insert();

Inserts glide record into Table. Returns sys id.

setValuesetValue(name, value)Example:

$glideRecord->setValue('caller_id','56');

Sets element within Glide Record with name to specified value. Will not effect the GlideRecord within the Tableuntil inserted or updated.

addQueryaddQuery(name, value)Example:

$glideRecord->addQuery('number','INC1000014');

$glideRecord->query();

Refines query to include only the Glide Records with field name=value.

Page 35: Using Perl With ServiceNow

GlideRecord.pm 34

queryquery(optional hash arguments)Example:

$glideRecord->query();

Returns all Glide Records in the Table with specified query. Step through the Records with the next() call.

nextnext()Example:

if($glideRecord->next());

while($glideRecord->next());

Steps through the results of Glide Record query. Returns TRUE if more elements exist.

updateupdate(optional hash arguments)Example:

$glideRecord->setValue('name','value');

$glideRecord->update();

Updates Glide Record in table with the Glide Record object. Changes to Glide Record object will not take effectuntil updated or inserted. Returns sys_id of record on success, undef of failure.

getValuegetValue(name)Example:

$glideRecord->getValue($name);

Get value of element name in GlideRecord. Returns string value of element.

getDisplayValuegetDisplayValue(name)Example:

$glideRecord->getDisplayValue($name);

Gets display value of element name in GlideRecord. A display value would be the string name, instead of the sys_idin the case of a reference field, or the string value instead of the number value in the case of choice fields.

Page 36: Using Perl With ServiceNow

Attachment.pm 35

Attachment.pm

Perl API

• ServiceNow.pm• ITIL Objects

• Incident.pm• Problem.pm• Change.pm• Request.pm• RequestedItem.pm• SC_Task.pm• Ticket.pm• Task.pm• Approval.pm

• Other

• Configuration.pm• GlideRecord.pm• Attachment.pm

Related Topics

• Integration Overview• Web Services

Get the Book

Get the Book

Attachment moduleServiceNow Perl API - Attachment perl module

DesciptionAn object representation of an Attachment in the ServiceNow platform. Provides subroutines for creating anattachment and attaching to an existing record

System RequirementsThe ServiceNow Perl API requires Perl 5.8 with the following modules installed• SOAP::Lite (prerequisites http:/ / soaplite. com/ prereqs. html) 0.71 or later• Crypt::SSLeay• IO::Socket::SSL• File::Basename• MIME::Types• MIME::Type• MIME::Base64

Page 37: Using Perl With ServiceNow

Attachment.pm 36

Constructor

newnew(Configuration);Example:

$task = ServiceNow::Attachment->new($CONFIG);

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

Subroutines

createcreate(path, table_name, sys_id)Example:$attachment->create("/Users/davidloo/Desktop/test_files/number_test.xls", "incident", "9d385017c611228701d22104cc95c371");

Creates an attachment from a file on the local disk, to an existing record defined by table_name and sys_id Returnsthe sys_id of the ecc_queue record, undef if failed

Page 38: Using Perl With ServiceNow

Article Sources and Contributors 37

Article Sources and ContributorsServiceNow.pm  Source: http://wiki.servicenow.com/index.php?oldid=80844  Contributors: David Loo, Joseph.messerschmidt, Rachel.sienko

Incident.pm  Source: http://wiki.servicenow.com/index.php?oldid=80839  Contributors: David Loo, Joseph.messerschmidt, Kenny.caldwell, Neola, Rachel.sienko

Problem.pm  Source: http://wiki.servicenow.com/index.php?oldid=80840  Contributors: David Loo, Joseph.messerschmidt, Neola, Rachel.sienko

Change.pm  Source: http://wiki.servicenow.com/index.php?oldid=80835  Contributors: David Loo, Joseph.messerschmidt, Rachel.sienko

Request.pm  Source: http://wiki.servicenow.com/index.php?oldid=80841  Contributors: David Loo, Joseph.messerschmidt, Rachel.sienko

RequestedItem.pm  Source: http://wiki.servicenow.com/index.php?oldid=80842  Contributors: David Loo, Joseph.messerschmidt, Rachel.sienko

SC_Task.pm  Source: http://wiki.servicenow.com/index.php?oldid=80843  Contributors: David Loo, Joseph.messerschmidt, Rachel.sienko

Ticket.pm  Source: http://wiki.servicenow.com/index.php?oldid=80846  Contributors: David Loo, Joseph.messerschmidt, Rachel.sienko

Task.pm  Source: http://wiki.servicenow.com/index.php?oldid=80845  Contributors: David Loo, Joseph.messerschmidt, Rachel.sienko

Approval.pm  Source: http://wiki.servicenow.com/index.php?oldid=80833  Contributors: David Loo, Joseph.messerschmidt, Rachel.sienko

Configuration.pm  Source: http://wiki.servicenow.com/index.php?oldid=183464  Contributors: David Loo, Jason.petty, Joseph.messerschmidt, Rachel.sienko

GlideRecord.pm  Source: http://wiki.servicenow.com/index.php?oldid=82161  Contributors: David Loo, Joseph.messerschmidt, Rachel.sienko

Attachment.pm  Source: http://wiki.servicenow.com/index.php?oldid=80834  Contributors: David Loo, Joseph.messerschmidt, Rachel.sienko

Page 39: Using Perl With ServiceNow

Image Sources, Licenses and Contributors 38

Image Sources, Licenses and ContributorsImage:Knowledge.gif  Source: http://wiki.servicenow.com/index.php?title=File:Knowledge.gif  License: unknown  Contributors: G.yedwab