How to use pipeline action: Evaluate JavaScript for accessing ServiceNow Tickets?
Overview
In pipeline action - Evaluate JavaScript following methods are available to access Service-Now ticketing API calls
Script Method - getServiceNowTickets('seekerEmailAddress')
To get list of tickets, script call will appear as follows:
//Get tickets
var tickets = getServiceNowTickets("${Guest.Email}");
In response method will return list of tickets JSON
[
{
"Seeker": "webvisitor@example.com",
"Agent": agent@example.com,
"Question": "Employee payroll application server is down.",
"ChatTranscript": "",
"Id": "f12ca184735123002728660c4cf6a7ef",
"Number": "INC0007001",
"URL": "https://dev82149.service-now.com/nav_to.do?url=incident.do?sys_id=f12ca184735123002728660c4cf6a7ef",
"UpdatedOn": "2023-06-07 12:24:46",
"TicketState": "New"
},
{
"Seeker": "webvisitor@example.com",
"Agent": "agent@exampple.com",
"Question": "Performance problems with wifi",
"ChatTranscript": "",
"Id": "78271e1347c12200e0ef563dbb9a7109",
"Number": "INC0000057",
"URL": "https://dev82149.service-now.com/nav_to.do?url=incident.do?sys_id=78271e1347c12200e0ef563dbb9a7109",
"UpdatedOn": "2023-05-29 13:20:52",
"TicketState": "New"
},
{
"Seeker": "webvisitor@example.com",
"Agent": "agent@example.com",
"Question": "Request for a Blackberry",
"ChatTranscript": "",
"Id": "b067a86a2f87a110ee31f64ef699b61d",
"Number": "INC0010002",
"URL": "https://dev82149.service-now.com/nav_to.do?url=incident.do?sys_id=b067a86a2f87a110ee31f64ef699b61d",
"UpdatedOn": "2023-05-29 13:18:44",
"TicketState": "In-Progress"
}
]
JSON response can be converted into an array
var ticketsArray = JSON.parse(tickets);
//Array allows you to get count and loop through ticket records etc...
sendReply("Count of tickets: " + ticketsArray.length);
Script Method - createServiceNowTicket('ticketJSON')
To create a ticket, in script create a ticket object as follows:
//Create ticket object
var ticket = {
state: '0',
short_description: 'Short Question',
description: 'Full Question',
caller_id: 'webvisitor@example.com',
assigned_to: 'admin@example.com',
work_notes: 'chat transcript'
};
//Convert object to JSON
var ticketJSON = JSON.stringify(ticket);
//Make API call to create ticket
var result = createServiceNowTicket(ticketJSON);
createServiceNowTicket call will return JSON response
{
"Seeker": "Web Visitor",
"Agent": "Agent",
"Question": "",
"ChatTranscript": "",
"Id": "8a0890212f572510ee31f64ef699b69d",
"Number": "INC0010004",
"URL": "https://dev82149.service-now.com/nav_to.do?url=incident.do?sys_id=8a0890212f572510ee31f64ef699b69d"
}
Script Method - updateServiceNowTicket('ticketJSON', ticketId)
To update ticket, in script create a ticket object with values to update, follows:
//Update ticket object
var ticket = {
short_description: 'Updated Short Question',
description: 'Updated Full Question',
work_notes: 'Updated chat transcript'
};
//Convert object to JSON
var ticketJSON = JSON.stringify(ticket);
//Make API call to update ticket
var result = updateServiceNowTicket(ticketJSON, <ticketId>);
updateServiceNowTicket call will return JSON response
{
"Seeker": "Web Visitor",
"Agent": "Agent",
"Question": "",
"ChatTranscript": "",
"Id": "8a0890212f572510ee31f64ef699b69d",
"Number": "INC0010004",
"URL": "https://dev82149.service-now.com/nav_to.do?url=incident.do?sys_id=8a0890212f572510ee31f64ef699b69d"
}
Related Items
To further enhance your understanding and utilization of the ticketing integration in Chime, here are some related resources:
- Elevating Service Desk Customer Support with Service-Now Ticketing Integration
- ServiceNow Ticket Listing
- Ticketing Metrics
API,
pipeline,
javascript,
service-now,
tickets,
incidents
vgarg