Chinaunix首页 | 论坛 | 博客
  • 博客访问: 310827
  • 博文数量: 118
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 1163
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-27 12:09
文章分类

全部博文(118)

文章存档

2023年(20)

2022年(3)

2021年(1)

2020年(1)

2019年(7)

2013年(2)

2011年(1)

2010年(37)

2009年(46)

我的朋友

分类: WINDOWS

2009-10-12 19:41:38

Example of VB2008 Express using ARAPI.NET to Create, Query and Modify an Incident Request

The attached document has example code for the creation, query and modification of an Incident Request using the HPD:IncidentInteface_Create and HPD:IncidentInterface forms supplied with the ITSM suite.

It show the usage of the API commands needed, and includes sub functions and classes to parse the command line for input arguments and for the login to Remedy (ARSInitialise).

Credit for excerpts of the code go to Pauln (ARSInitialise) and Appajee who have answered numerous discussions surrounding the .NET API.

The code is fully commented explaining the different usage, examples and calls needed to perform the different actions.

It is available as is and can be modified to suit each persons individual needs.

Refer to the BMC Remedy AR System discussions for further examples and support surrounding the API.

 

 

The following can be compiled using VS2008 and copied into a new project.  The ARAPI 7.1 was used.  Copy the following code into a new project and add a reference to the BMC.ARSystem.dll in the directory where you installed the ARAPI.

 

To use the program, supply the required parameters in the cmd line call:

 

consolecreateticket.exe -s itsm7rtm -u Demo -p password -t 0 -f Bob -l Backline

 

 

' ** Add a reference to the BMC.ARSystem.dll file in the Project
' References to External .dll Files
Imports BMC
Imports System

Module Module1

    ' Public Module Declarations (Available Throughout Module)
    Public ARSServer As New BMC.ARSystem.Server
    Public ARServerName As String
    Public ARServerPort As String
    Public ARUser As String
    Public ARPassword As String

    ' // Start of Main Routine in Module, Capture Input Parameters
    Public Sub Main(ByVal CmdLineArgs() As String)
        ' // This program will perform the following:
        ' // 1. Create a new Incident Request via the HPD:IncidentInteface_Create form
        ' // 2. Query the HPD:IncidentInteface_Create form for Incident Number
        ' // 3. Query the HPD:IncidentInteface form for the Entry ID for use with the modify function
        ' // 4. Send a Modify command and parameters the HPD:IncidentInteface form to Close the Incident Request
    

        ' // Input Parameters are:
  ‘ // -s ARServer, -u ARUser, -p ARPassword, -t ARServerPort, -f RequesterFirstName, -l RequesterLastName
        ' // ** Password cannot be blank **
        ' // The Create Uses Auto Assignment. Fill in the required fields to use manual Assignment.
        ' // Extra cmd line Parameters will be needed for Company, Org, Support Group if manual assignment required
     ‘ // or they can be hardcoded.
        ' // ARUser must be someone with Incident Modify permission (e.g. Incident Master) and be in the same Support Group as Assignment.

        ' // Define the required variables
        Dim ErrMsg As String = String.Empty
        Dim ARForm As String = "HPD:IncidentInterface_Create"
        Dim IntInterfaceEntryID As String
        Dim strIncidentID As String
        Dim strEntryID As String
        Dim strSQL As String
        Dim FieldList As New BMC.ARSystem.FieldValueList
        Dim EntryFieldList = New BMC.ARSystem.EntryListFieldList
        Dim EntryFieldValueList = New BMC.ARSystem.EntryFieldValueList
        Dim strFirstName As String
        Dim strLastName As String

        Try
            ' // Extract parameters from cmd line.
            ARServerName = GetArgValue(CmdLineArgs, "-s", ErrMsg)
            ARUser = GetArgValue(CmdLineArgs, "-u", ErrMsg)
            ARPassword = GetArgValue(CmdLineArgs, "-p", ErrMsg)
            ARServerPort = GetArgValue(CmdLineArgs, "-t", ErrMsg)
            strFirstName = GetArgValue(CmdLineArgs, "-f", ErrMsg)
            strLastName = GetArgValue(CmdLineArgs, "-l", ErrMsg)


            ' Below is the list of Minimum Fields Required by HPD:IncidentInterface_Create to create an Entry in HPD:HelpDesk
            ' ** Note - Auto Assignment Rule needed on Incident form, else you need to populate the following Fields: **
            ' Support Company*
            ' Support Organization*
            ' Support Group*
            ' Assigned Group Shift Name
            ' Assignee
            ' Login ID for Assignee

            FieldList.Add(1000000076, "CREATE") ' // Keyword Triggers the Create
            FieldList.Add(1000000018, strLastName) ' // Last_Name
            FieldList.Add(1000000019, strFirstName) ' // First_Name
            FieldList.Add(7, 1) ' // Status
            FieldList.Add(1000000099, 3) ' // Service_Type
            FieldList.Add(1000000163, 4000) ' // Impact
            FieldList.Add(1000000162, 4000) ' // Urgency
            FieldList.Add(1000000000, "Remedy Test Ticket From API")             ' // Description
            FieldList.Add(1000000215, 10000) ' // Reported Source

            ' // Optional for SRM Request Creation
            'FieldList.Add(301674600, "Yes") '// Flag_Create_Request - Required to create SRM Request Entry

            ' // ** Call Login Function within ARSHelper Class **
            ARSServer = ARSInitialise.Login

            ' // ** Create the Entry in HPD:IncidentInterface_Create with above Field List **
            ' // ** Returns the Request ID (Field ID 1) from the HPD:IncidentInterface_Create Form **
            IntInterfaceEntryID = ARSServer.CreateEntry(ARForm, FieldList)

            ' // ** Create SQL Query for GetListEntryWithFields Method **
            ' // We are wanting to use the ID returned in the Create above - this is our reference
            ' // * Example Query *
            ' // e.g. strSQL = "'1' = " & "00000000000006"
            strSQL = "'1' = " & IntInterfaceEntryID

            ' // Add The Field(s) We Want To Bring Back From The Form to the Entry Field List to parse in the method
            ' // e.g. Incident Number
            EntryFieldList.AddField(1000000161) '//Incident Number
            'EntryFieldList.AddField(1000000560) '//Reported Date*
            'EntryFieldList.AddField(301572100) '//SRID
            'EntryFieldList.AddField(1000000082) '//Contact Company*
            'EntryFieldList.AddField(1000000164) '//Priority

            ' // ** Return the Incident ID* from the call
            EntryFieldValueList = ARSServer.GetListEntryWithFields("HPD:IncidentInterface_Create", strSQL, EntryFieldList, 0, 50)
            strIncidentID = ""


            ' // If returning more than one entry, use a for loop
            For Each entryFieldValue In EntryFieldValueList
                strIncidentID = entryFieldValue.FieldValues(1000000161)
                Console.Write("Incident ID* = ")
                Console.WriteLine(entryFieldValue.FieldValues(1000000161))
            Next

            ' // NOTE: Query required for HPD:IncidentInterface differs from above as we are specifying a particular field by name
            ' // Example SQL Query ** Note: Inverted Commas Needed or SQL Will Fail**
            ' // strSQL = "'Incident Number' = ""INC000000000093"""
            strSQL = "'Incident Number' = """ + strIncidentID + """"

            ' // Retrieve Required Entry ID from HPD:IncidentInterface for Modify (Close) Action
            EntryFieldList.Clear()
            EntryFieldList.AddField(1) '//Entry ID

            EntryFieldValueList = ARSServer.GetListEntryWithFields("HPD:Help Desk", strSQL, EntryFieldList, 0, 1)
            strEntryID = ""

            For Each entryFieldValue In EntryFieldValueList
                strEntryID = entryFieldValue.FieldValues(1)
                Console.Write("EntryID = ")
                Console.WriteLine(entryFieldValue.FieldValues(1))
            Next


            ' // Close Out the Incident by supplying Resolution, Status, Status Reason and Assignee information
            ' // Assignee information is required on different setups, so best to include it for safety
            FieldList.Clear()
            FieldList.Add(1000000076, "MODIFY") ' // Keyword Triggers the Modify
            FieldList.Add(1000000156, "API Automatic Resolution")     ' // Resolution
            FieldList.Add(1000000150, "No Further Action Required") ' // Status Reason
            FieldList.Add(7, "Closed") ' // Status
            FieldList.Add(1000000218, (strFirstName & " " & strLastName)) ' // Asignee
            FieldList.Add(4, ARUser) ' // Login ID of Assignee
            strSQL = strEntryID ' // Entry ID of HPD:IncidentInterface


            ARSServer.SetEntry("HPD:IncidentInterface", strSQL, FieldList) ' // Close Incident

        Catch ex As BMC.ARSystem.ARException

            Throw New System.Exception(ex.Message, ex.InnerException)
            Exit Sub

        Catch ir As Exception

            Throw New System.Exception(ir.Message, ir.InnerException)

        End Try
    End Sub

    ' // Function to return values from command line.
    Function GetArgValue(ByRef ArgArray() As String, ByVal SwitchValue As String, ByRef ErrMsg As String) As String
        ' Return switch values from command line.
        ' Switches and values must only come in pairs, ie. -u User -p Password -s Server
        Try
            For i As Integer = 0 To UBound(ArgArray) Step 2
                If ArgArray(i) = SwitchValue Then
                    Return ArgArray(i + 1)
                End If
            Next
        Catch ex As Exception
            ErrMsg = ex.Message
        End Try
        Return String.Empty
    End Function

    ' // Class To Log Into ARServer
    Public Class ARSInitialise
        ' // Parameters Obtained From Cmd Line Input
        Public Shared Function Login() As ARSystem.Server
            Try

                Dim RemedyServer As New ARSystem.Server
                'RemedyServer.Login(server:=, user:=, password:=, port:=)
                RemedyServer.Login(ARServerName, ARUser, ARPassword)
                'RemedyServer.SetServerPort(port:=, rpcProgramNum:=)
                RemedyServer.SetServerPort(ARServerPort, 0)

                Dim UserInfo() As ARSystem.UserInfo = RemedyServer.GetListUser(ARSystem.Server.UserListType.Myself, New Date(2000, 1, 1))

                Return RemedyServer

            Catch ex As Exception

                Throw New System.Exception(ex.Message, ex.InnerException)
                Exit Function

            End Try
        End Function
    End Class
End Module


阅读(3452) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~