I am currently trying to make an ingestion tool that takes an email sent into Outlook and with one click allows all the information to be uploaded to a ticket in ServiceNow.
The issue I am having is that when the ticket is created in service now it either logs the ticket under the name "IT service desk" instead of the customer's name.
The way I have figured out how to get it to log it under the customer name then also adds a line of text in the description saying "incident logged by #(username) which again I do not want.
I cannot remove one without the other, so if I remove the line of code that removes the "Incident logged by #(username) it then also stops autopopulating the customer name. If I leave the "Incident logged by #(username) it does automatically populate the correct name.
I have added "company email address" below instead of the actual address.
Const olMail As Integer = 43
Sub SNTicket()
Dim servicenowaddress As String
Dim objMail As Outlook.MailItem
Dim strbody As String
Dim senderAddress As String
Dim addresstype As Integer
' ServiceNow email address for the ticket recipient
servicenowaddress = "Company email address"
' Get the currently selected item in Outlook
Set objItem = GetCurrentItem()
' Check if the item is a mail item
If Not objItem Is Nothing And objItem.Class = olMail Then
' Create a new mail item for forwarding
Set objMail = objItem.Forward
' Sender E-mail Address
senderAddress = objItem.SenderEmailAddress
' Searches for @ in the email address to determine if it is an exchange user
addresstype = InStr(senderAddress, "@")
' If the address is an Exchange DN, use the Senders Name
If addresstype = 0 Then
senderAddress = objItem.senderName
End If
' Configure the forwarding mail item
objMail.To = servicenowaddress
objMail.Subject = "#NoSig " & objItem.Subject
objMail.Body = vbNewLine & vbNewLine & objItem.Body
' Remove the comment from below to display the message before sending
' objMail.Display
' Automatically send the ticket
objMail.Send
Else
MsgBox "This is not a valid mail item.", vbExclamation
End If
' Clean up
Set objItem = Nothing
Set objMail = Nothing
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
' Determine the currently active window in Outlook
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
Case Else
Set GetCurrentItem = Nothing
End Select
On Error GoTo 0
End Function