Tutorial: Autofill HP Service Manager (HPSM)

So I’ve been asked by a couple of people how I managed to autofill a new HP Service Manager Service Ticket. This is what my company uses for service ticket handling and what not. The IRIS program is able to auto-submit tickets when a device fails a certain amount of times. Here’s the code!

Public Class serviceTicketForm
    Dim numFramesLoaded As Integer = 0
    Dim storeName As String = ""
    Dim newLocation As String = ""
    Dim description As String = ""

    Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If My.Settings.certServer = CheckState.Checked Then
            'Certification environment
            wb2.Navigate("<a href="https://certificationserver:port/webtier-7.01/ess.do">https://certificationserver</a>")
            'Production environment
            wb2.Navigate("<a href="https://productionserver:port/webtier-7.01/ess.do">https://productionserver</a>")
        End If

        numFramesLoaded = 0

        'Set window location to bottom right corner
        'Me.Top = (frmMain.Top + frmMain.Height) - (Me.Height + 15)
        'Me.Left = (frmMain.Left + frmMain.Width) - (Me.Width + 15)
    End Sub

    Private Sub autoLogin()
        Dim username As String = My.Settings.TicketUsername
        Dim password As String = My.Settings.TicketPassword
            'Username (Default is Windows Credentials)
            wb2.Document.Window.Frames(1).Document.GetElementById("X2").SetAttribute("Value", username)
            wb2.Document.Window.Frames(1).Document.GetElementById("X5").SetAttribute("Value", password)
            '"Click" the button
        Catch ex As Exception
        End Try
    End Sub

    Private Sub fillForm()
        Dim methodOfContact As String = "Email"  'Sets the method of contact to "Email" so that I get an email response back when the ticket is closed

            'Preferred Method of Contact
            wb2.Document.Window.Frames(1).Document.GetElementById("X8").SetAttribute("Value", methodOfContact)

            'Location needing service
            getLocationFromIP() 'Calculates the location name based on the Device name. This is custom to my use, so it will vary for yours
            'You could also just set newLocation equal to a known value of the drop down box
            wb2.Document.Window.Frames(1).Document.GetElementById("X24").SetAttribute("Value", newLocation)
            wb2.Document.Window.Frames(1).Document.GetElementById("X24").InvokeMember("onkeyup") 'This forces the dropdown box to do the lookup and register the change

            'Description of the service being requested
            wb2.Document.Window.Frames(1).Document.GetElementById("X29").SetAttribute("Value", description) 'This fills in the description of the needed service

            'Submit the thing!
            wb2.Document.Window.Frames(1).Document.GetElementById("X31").InvokeMember("click") 'Clicks the submit button!

        Catch ex As Exception
        End Try
    End Sub

    Private Sub getLocationFromIP()
        Dim ip As String = frmMain.recordersOfflineLV.Items(frmMain.recordersOfflineLV.Items.Count - 1).SubItems(1).Text
        Dim corp1 As String = ""
        Dim corp2 As String = ""
        Dim corp3 As String = ""

        corp1 = ip.Substring(6, 1)
        corp2 = ip.Substring(9, 1)
        corp3 = ip.Substring(10, 1)
        newLocation = "00"
        newLocation = String.Concat(corp1, corp2, corp3)
    End Sub

    Private Sub getDescription()

        description = "This is where your service ticket text goes. The description of the service needed. etc.."

    End Sub

    Private Sub waitThenClose_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles waitThenClose.Tick
        If My.Settings.certServer = CheckState.Checked Then
            'Certification Environment
            wb2.Navigate("<a href="https://certificationserver:8443/webtier-7.01/cwc/goodbye.jsp">https://certificationserver/cwc/goodbye.jsp</a>")
            'Production Environment
            wb2.Navigate("<a href="https://productionserver:8443/webtier-7.01/cwc/goodbye.jsp">https://productionserver/webtier-7.01/cwc/goodbye.jsp</a>")
        End If
    End Sub

    Private Sub wb2_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles wb2.DocumentCompleted
        numFramesLoaded += 1
        Select Case numFramesLoaded 'Counts the frames that have loaded so that I know which page it is currently on.
            Case 8 'Tells me it is the Login Page
                'Login page
                statusLabelTicket.Text = Environment.NewLine  "Logging in..."
            Case 10 'Tells me it is the Form Page
                'Service page
                statusLabelTicket.Text = Environment.NewLine  "Processing..."
            Case 11 'Tells me it is ready for Log Out Page.
                'Logout cleanly
                If My.Settings.certServer = CheckState.Checked Then
                    'Certification Environment
                    wb2.Navigate("<a href="https://certificationserver:8443/webtier-7.01/cwc/logoutcleanup.jsp">https://certificationserver/cwc/logoutcleanup.jsp</a>")
                    'Production Environment
                    wb2.Navigate("<a href="https://productionserver:8443/webtier-7.01/cwc/logoutcleanup.jsp">https://productionserver/webtier-7.01/cwc/logoutcleanup.jsp</a>")
                End If
                statusLabelTicket.Text = Environment.NewLine  "Submitted!"  Environment.NewLine  "Logging out..."
            Case 13 'Tells me it logged out cleanly
        End Select
    End Sub
End Class

Things you will need to check: You can see that I have a cert server and a production server available. I have a checkbox on my main form that lets me toggle between the two, for testing. I don’t want to send fake tickets to the Service Desk team.. They tend to hate me when I do that 🙂

Also, ‘statusLabelTicket’ is a label that basically states what the current progress is on the form.

The getLocationFromIP() procedure basically converts the device’s IP address into a Store Location. This will not be applicable to most people and will need to be edited or deleted where necessary.

Have fun!

Comments welcome.

One thought on “Tutorial: Autofill HP Service Manager (HPSM)

Leave a Reply

Your email address will not be published. Required fields are marked *