class SysAid::Ticket

Attributes

agreement[RW]
archive[RW]
assign_counter[RW]
assigned_group[RW]
assigned_to[RW]
category[RW]
cc[RW]
change_category[RW]
ciid[RW]
close_time[RW]
closure_information[RW]
computer_id[RW]
current_support_level[RW]
cust_int1[RW]
cust_int2[RW]
cust_list1[RW]
cust_list2[RW]
cust_notes[RW]
cust_text1[RW]
cust_text2[RW]
description[RW]
email_account[RW]
escalation[RW]
followup_text[RW]
id[RW]
impact[RW]
insert_time[RW]
location[RW]
max_support_level[RW]
notes[RW]
priority[RW]
project_id[RW]
reopen_counter[RW]
request_user[RW]
resolution[RW]
solution[RW]
source[RW]
sr_sub_type[RW]
sr_type[RW]
status[RW]
sub_category[RW]
submit_user[RW]
success_rating[RW]
task_id[RW]
third_level_category[RW]
title[RW]
update_time[RW]
update_user[RW]
urgency[RW]
user_manager[RW]
version[RW]
workaround[RW]

Public Class Methods

find_by_id(ticket_id) click to toggle source
# File lib/sysaid/ticket.rb, line 72
def self.find_by_id(ticket_id)
  ticket = SysAid::Ticket.new

  ticket.id = ticket_id

  return nil unless ticket.refresh

  return ticket
end
find_by_query(query) click to toggle source
# File lib/sysaid/ticket.rb, line 82
def self.find_by_query(query)
  SysAid.ensure_logged_in

  response = SysAid.call(:execute_select_query, message: sql_query(query))

  if response.to_hash[:execute_select_query_response][:return]
    return response.to_hash[:execute_select_query_response][:return]
  end

  return false
end
new() click to toggle source
# File lib/sysaid/ticket.rb, line 12
def initialize
  reset_all_attributes
end

Private Class Methods

sql_query(query) click to toggle source
# File lib/sysaid/ticket.rb, line 278
def self.sql_query(query)
  builder = Builder::XmlMarkup.new

  builder.sessionId(SysAid.session_id)
  xml = builder.apiSysObj('xsi:type' => "tns:apiServiceRequest")
  xml = builder.condition(query)

  xml
end

Public Instance Methods

add_note(user, note, time = Time.now) click to toggle source

Though the 'notes' field is merely an editable string, 'add_note' mimics the behavior of the SysAid web client.

# File lib/sysaid/ticket.rb, line 110
def add_note(user, note, time = Time.now)
  # NOTE: Notes are prepended.
  new_note = "#{user} (#{time.strftime("%-m/%-d/%y %I:%M %p")}):\n   #{note}"

  if self.notes
    self.notes = new_note + "\n=============================\n" + self.notes
  else
    self.notes = new_note
  end
end
delete() click to toggle source

Deletes a ticket from the SysAid server

No return value as SysAid's 'delete' call returns void. No idea why.

Example:

>> ticket_object.delete
=> true
# File lib/sysaid/ticket.rb, line 147
def delete
  SysAid.ensure_logged_in

  SysAid.call(:delete, message: to_xml(false))

  reset_all_attributes
end
refresh() click to toggle source

Loads the latest ticket information from the SysAid server

# File lib/sysaid/ticket.rb, line 95
def refresh
  SysAid.ensure_logged_in

  response = SysAid.call(:load_by_string_id, message: to_xml)

  if response.to_hash[:load_by_string_id_response][:return]
    set_self_from_response(response.to_hash[:load_by_string_id_response][:return])
    return true
  end

  return false
end
reset_all_attributes() click to toggle source

Needed by both initialize and delete (to empty out the object when deleted)

# File lib/sysaid/ticket.rb, line 17
def reset_all_attributes
  self.agreement = nil
  self.archive = nil
  self.assign_counter = nil
  self.assigned_group = nil
  self.assigned_to = nil
  self.ciid = nil
  self.category = nil
  self.cc = nil
  self.change_category = nil
  self.close_time = Date.new
  self.closure_information = nil
  self.computer_id = nil
  self.current_support_level = nil
  self.cust_int1 = nil
  self.cust_int2 = nil
  self.cust_list1 = nil
  self.cust_list2 = nil
  self.cust_notes = nil
  self.cust_text1 = nil
  self.cust_text2 = nil
  self.description = nil
  self.email_account = nil
  self.escalation = nil
  self.followup_text = nil
  self.id = nil
  self.impact = nil
  self.insert_time = Date.new
  self.location = nil
  self.max_support_level = nil
  self.notes = nil
  self.parent_link = nil
  self.priority = nil
  self.project_id = nil
  self.reopen_counter = nil
  self.request_user = nil
  self.resolution = nil
  self.solution = nil
  self.source = nil
  self.sr_sub_type = nil
  self.sr_type = nil
  self.status = nil
  self.sub_category = nil
  self.success_rating = nil
  self.task_id = nil
  self.third_level_category = nil
  self.title = nil
  self.update_time = Date.new
  self.update_user = nil
  self.urgency = nil
  self.user_manager = nil
  self.version = nil
  self.workaround = nil
end
save() click to toggle source

Saves a ticket back to the SysAid server

Example:

>> ticket_object.save
=> true
# File lib/sysaid/ticket.rb, line 126
def save
  SysAid.ensure_logged_in

  # Save it via the SOAP API
  response = SysAid.call(:save, message: to_xml(false))
  if response.to_hash[:save_response][:return]
    # In the case of a new ticket, the SysAid response will be the assigned ID
    self.id = response.to_hash[:save_response][:return] unless self.id
    return true
  else
    return false
  end
end

Private Instance Methods

set_self_from_response(response) click to toggle source

Update instance variables to match what is in response

# File lib/sysaid/ticket.rb, line 223
def set_self_from_response(response)
  self.agreement = response[:agreement]
  self.archive = response[:archive]
  self.assign_counter = response[:assign_counter]
  self.assigned_group = response[:assign_group]
  self.assigned_to = response[:assign_to]
  self.ciid = response[:ci_id]
  self.category = response[:category]
  self.cc = response[:cc]
  self.change_category = response[:change_category]
  self.close_time = response[:close_time] if response[:close_time]
  self.closure_information = response[:closure_information]
  self.computer_id = response[:computer_id]
  self.current_support_level = response[:current_support_level]
  self.cust_int1 = response[:cust_int1]
  self.cust_int2 = response[:cust_int2]
  self.cust_list1 = response[:cust_list1]
  self.cust_list2 = response[:cust_list2]
  self.cust_notes = response[:cust_notes]
  self.cust_text1 = response[:cust_text1]
  self.cust_text2 = response[:cust_text2]
  self.description = response[:description]
  self.email_account = response[:email_account]
  self.escalation = response[:escalation]
  self.followup_text = response[:followup_text]
  self.id = response[:id]
  self.impact = response[:impact]
  self.insert_time = response[:insert_time]
  self.location = response[:location]
  self.max_support_level = response[:max_support_level]
  self.notes = response[:notes]
  self.parent_link = response[:parent_link]
  self.priority = response[:priority]
  self.project_id = response[:project_id]
  self.reopen_counter = response[:reopen_counter]
  self.request_user = response[:request_user]
  self.resolution = response[:resolution]
  self.solution = response[:solution]
  self.source = response[:source]
  self.sr_sub_type = response[:sr_sub_type]
  self.sr_type = response[:sr_type]
  self.status = response[:status]
  self.sub_category = response[:sub_category]
  self.success_rating = response[:success_rating]
  self.task_id = response[:task_id]
  self.third_level_category = response[:third_level_category]
  self.title = response[:title]
  self.update_time = response[:update_time]
  self.update_user = response[:update_user]
  self.urgency = response[:urgency]
  self.user_manager = response[:user_manager]
  self.version = response[:version]
  self.workaround = response[:workaround]
end
to_xml(include_id = true) click to toggle source
# File lib/sysaid/ticket.rb, line 157
def to_xml(include_id = true)
  builder = Builder::XmlMarkup.new

  builder.sessionId(SysAid.session_id)
  xml = builder.apiSysObj('xsi:type' => "tns:apiServiceRequest") { |b|
    b.agreement(self.agreement, 'xsi:type' => 'xsd:int')
    b.archive(self.archive, 'xsi:type' => 'xsd:boolean')
    b.assignCounter(self.assign_counter, 'xsi:type' => 'xsd:int')
    b.assignedGroup(self.assigned_group, 'xsi:type' => 'xsd:string')
    b.assignedTo(self.assigned_to, 'xsi:type' => 'xsd:string')
    b.CIId(self.ciid, 'xsi:type' => 'xsd:int')
    b.category(self.category, 'xsi:type' => 'xsd:string')
    b.cc(self.cc, 'xsi:type' => 'xsd:string')
    b.changeCategory(self.change_category, 'xsi:type' => 'xsd:int')
    b.closeTime(self.close_time.rfc3339, 'xsi:type' => 'xsd:dateTime')
    b.closureInformation(self.closure_information, 'xsi:type' => 'xsd:int')
    b.computerID(self.computer_id, 'xsi:type' => 'xsd:string')
    b.currentSupportLevel(self.current_support_level, 'xsi:type' => 'xsd:int')
    b.custInt1(self.cust_int1, 'xsi:type' => 'xsd:int')
    b.custInt2(self.cust_int2, 'xsi:type' => 'xsd:int')
    b.custList1(self.cust_list1, 'xsi:type' => 'xsd:int')
    b.custList2(self.cust_list2, 'xsi:type' => 'xsd:int')
    b.custNotes(self.cust_notes, 'xsi:type' => 'xsd:string')
    b.custText1(self.cust_text1, 'xsi:type' => 'xsd:string')
    b.custText2(self.cust_text2, 'xsi:type' => 'xsd:string')
    b.customDateFields
    #b.customFields
    b.description(self.description, 'xsi:type' => 'xsd:string')
    b.emailAccount(self.email_account, 'xsi:type' => 'xsd:string')
    b.escalation(self.escalation, 'xsi:type' => 'xsd:int')
    b.followupText(self.followup_text, 'xsi:type' => 'xsd:string')
    b.id(self.id, 'xsi:type' => 'xsd:int')
    b.impact(self.impact, 'xsi:type' => 'xsd:int')
    b.insertTime(self.insert_time.rfc3339, 'xsi:type' => 'xsd:dateTime')
    b.location(self.location, 'xsi:type' => 'xsd:int')
    b.maxSupportLevel(self.max_support_level, 'xsi:type' => 'xsd:int')
    b.notes(self.notes, 'xsi:type' => 'xsd:string')
    b.parentLink(self.parent_link, 'xsi:type' => 'xsd:int')
    b.priority(self.priority, 'xsi:type' => 'xsd:int')
    b.projectID(self.project_id, 'xsi:type' => 'xsd:int')
    b.reopenCounter(self.reopen_counter, 'xsi:type' => 'xsd:int')
    b.requestUser(self.request_user, 'xsi:type' => 'xsd:string')
    b.resolution(self.resolution, 'xsi:type' => 'xsd:string')
    b.solution(self.solution, 'xsi:type' => 'xsd:string')
    b.source(self.source, 'xsi:type' => 'xsd:int')
    b.srSubType(self.sr_sub_type, 'xsi:type' => 'xsd:int')
    b.srType(self.sr_type, 'xsi:type' => 'xsd:int')
    b.status(self.status, 'xsi:type' => 'xsd:int')
    b.subCategory(self.sub_category, 'xsi:type' => 'xsd:string')
    b.successRating(self.success_rating, 'xsi:type' => 'xsd:int')
    b.taskID(self.task_id, 'xsi:type' => 'xsd:int')
    b.thirdLevelCategory(self.third_level_category, 'xsi:type' => 'xsd:string')
    b.title(self.title, 'xsi:type' => 'xsd:string')
    b.updateTime(self.update_time.rfc3339, 'xsi:type' => 'xsd:dateTime')
    b.updateUser(self.update_user, 'xsi:type' => 'xsd:string')
    b.urgency(self.urgency, 'xsi:type' => 'xsd:int')
    b.userManager(self.user_manager, 'xsi:type' => 'xsd:string')
    b.version(self.version, 'xsi:type' => 'xsd:int')
    b.workaround(self.workaround, 'xsi:type' => 'xsd:string')
  }
  xml = builder.id(self.id) if include_id

  xml
end