Generating Incidents with WebServices and the ASDK

Generating Incidents with WebServices and the ASDK

You can use the ASDK to programmatically generate incidents but you are limited to using the subject and body fields when creating them. You can then use the ASDK to modify fields one by one, which means if you are changing 5+ fields the workers will have to scroll halfway down the page to view the body of an incident.

You can generate tickets by accessing the ProcessWorkItem operation of the Helpdesk webservice (AeXHD). I wanted to return the ticket number generated so I used an XML reader to call the URL and read the xml data it returns. One thing to note is that the content is being sent to the server via GET so it has to be encoded prior to sending it. In .NET there is a method called Uri.EscapeDataString(string) You have to use this to encode your field content before sending it to the webserver.

You can then call the webservice and read the xml data it returns to get the ticket number. This will create a ticket and modify all of your field values in one operation (incident event). You will need to create a active directory account and a new helpdesk worker account which is linked to the domain account via the NT_ID.

Here is the code I used to generate a ticket, I am using visual studio 2008 and c# in my example:

using System;
using System.Net;
using System.Xml;
using System.Management;
using System.DirectoryServices;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace TicketGenSample
{
  class Program
  {

    static void Main(string[] args)
    {
		string EncodedTicketTitle = Uri.EscapeDataString("Ticket Title Goes Here");
		string EncodedAssignToWorker = Uri.EscapeDataString("worker");
		string EncodedCategory = Uri.EscapeDataString("break - fix");
		string EncodedTicketBody = Uri.EscapeDataString("Ticket Body Goes Here");


		string TicketNumber = GenTicket("http://webserver/AeXHD/WebService.asmx/ProcessWorkItem?workitem_title=" + EncodedTicketTitle + " 	&workitem_owned_by_worker_id=" + EncodedAssignToWorker + " 	&workitem_category_tree_value=" + EncodedCategory + " 	&workitem_comment=" + EncodedTicketBody + " 	&priority_lookup=300 	&workitem_link_parent_number=1 	&workitem_assigned_to_worker_id=1");
        Console.WriteLine("Ticket Number: " + TicketNumber);
    }


    static string GenTicket(string HappyUrl)
    {
      string ReturnVal = null;
      XmlUrlResolver authenticator = new XmlUrlResolver();
      NetworkCredential credentials = new
      NetworkCredential("username", "password", "domain");
      CredentialCache creCache = new CredentialCache();
      creCache.Add(new Uri("http://webserverHostName"), "NTLM", credentials);
      authenticator.Credentials = creCache;
      XmlTextReader xml = new
      XmlTextReader(HappyUrl);
      xml.XmlResolver = authenticator;
      xml.WhitespaceHandling = WhitespaceHandling.None;
      while (xml.Read())
      {
        if (xml.NodeType.ToString() == "Text" && ReturnVal == null)
        {
          ReturnVal = xml.Value.ToString();
        }
      }
      return ReturnVal;
    }
  }
}

If you have any questions or want me to post the complete solution to this project let me know!

3.612245
Average: 3.6 (49 votes)

I've been looking for this solution for a long time!

Thanks so much. Can you e-mail the full solution to me at rpincus@nationalgypsum.com? Thanks

Rick

Primary contact

How would you specify the primary contact?

thanks,
-tj