Quick assign to analyst, SMLets?
I posted this in the SMLets thread but didn't want to clog it up asking for additional help. I am trying to figure out a way to be able to forward an email and have it quick create and assign to a specific analyst. This can be via the email emailed or the subject or body. So far I have been trying to do it with the recipient email, but without making 20 mailboxes that all have individual redirect rules (which DOES work with SMLets Multi Mailbox feature I am just trying to do it without maintaining a bunch of mailboxes). Using transport rules though it is not possible to handle BCC because it is not written to a header and therefore cannot be matched by SMLets.
After much research it seems like the custom events script might be able to do what I want via subject or body. I think I just need a little help with the steps (I am not an SCSM guy)
-Copy smletsExchangeConnector_customEvents.ps1 somewhere to server and .dot source it into the SMLets config page under DLL
-Add some code to Invoke-AfterCreateSR (we only use SRs pretty much) function within the customEvents script, something like below (ripped from another thread and modified). Would this work? Is $newWorkItem.ID correct? If nothing hits in this switch statement would it then proceed normally or do I need to account for that? Are there other good examples floating around I could copy? I am also open to other ways to do it.
function Invoke-AfterCreateIR { # This function occurs after a new incident work item is created. $ID = $NewWorkItem.ID ### I am guessing here based off custom events examples $SRClass = Get-SCSMClass -name System.WorkItem.ServiceRequest$ $UserClass = Get-SCSMClass -name System.Domain.User$ $AssignedToUserRelClass = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser$ $ServiceRequest = Get-SCSMObject -Class $SRClass -Filter "ID -eq $ID" #Maybe I could use $newWorkItem instead of doing the $serviceRequest lookup on the ID? Switch -wildcard $email.Subject { '*[USER1]*' { try { $User = Get-SCSMObject -Class $UserClass -Filter "Username -eq 'USER1'" New-SCSMRelationshipObject -RelationShip $AssignedToUserRelClass -Source $Incident -Target $User -Bulk } catch { $logMessage = $_.Exception.Message New-SMEXCOEvent -Source "CustomEvents" -EventId 25 -LogMessage $logMessage -Severity "Error" } } '*[USER2]*'{ try { $User = Get-SCSMObject -Class $UserClass -Filter "Username -eq 'USER2'" New-SCSMRelationshipObject -RelationShip $AssignedToUserRelClass -Source $Incident -Target $User -Bulk } catch { $logMessage = $_.Exception.Message New-SMEXCOEvent -Source "CustomEvents" -EventId 25 -LogMessage $logMessage -Severity "Error" } } } }
Thank you!
EDIT: Updated example code to show my new wisdom about relationships and assigning the analyst. I got this to work in a small example script where I explicitly defined the SR# and User, just trying to translate it to custom events automation now.
Comments
So when poeple are writing an email they send it to the corresponding Analyst in bcc? Why not in cc, as cc gets saved into the $email object inside the exchange connector and then you could easily assign it to the analyst who is mentioned.
People use to, cc, and bcc (for varying use cases). I want to support all of them (I currently have it working with TO/CC via transport rules). I honestly don't think it is possible without using tons of extra mailboxes + redirect which is why I wanted to look into subject based processing (something we always wanted to mess with). I would try my code but I don't really know how to debug it with SMLets running as a mgmt pack and custom events dot sourced in so just looking for some feedback.
Bcc is a way to hide recipients on purpose and after some searching, there is no way finding it in the header. Imo it is like decrypting an encrypted password with no key - if it was possible, the encryption wouldn't make any sense - and it's the same with BCC (maybe not exactly the same but I guess you get what I mean 😉 )
I guess the easiest way around would bring people to use cc if they want SRs to be automatically assigned.
To the customevents, the variables are correct. Still I wouldn't recommend searching a user via some information in square brackets. We use square brackets for direct group assignment, be it via Support Group names or certain key words, and what can I say: It seems there are so many stumbling blocks (Some are not able to differentiate between [ and {, others forget the square brackets as a whole, misspelling, etc. etc.) with that.
And you really want end users to be able to assign an SR or Incident directly based on the user they mention in to, cc or bcc? May I ask why you wanna do that? I guess if I implemented such thing in our company, the whole IT would chase me away with torches 😁
I think we agree on inability to use BCC here. Like I said, I want to support it. It is just easier to throw in a BCC when you are replying to a thread you know has to end up with a certain analyst and not risk all the replies making new tickets or exposing the 'secret' email to random people. All of this is for internal use within my IT group only. We constantly use this to assign certain things to certain analysts as quickly as possible and to do scheduled tickets to certain people. I may also want to expand subject based routing in the future now that I have started messing with it.
You think my code looks ok? Is your main issue with using brackets in the subject just because you think users would mess it up? I am not worried about that since we are only using it internally. Worst case they typo it, it makes an unassigned ticket as normal. Based on another thread I read from Adam looks like I would be able to debug this by doing the following? I guess I am not sure how to include the custom events in the debugging if I do it this way
Thanks for replying Simon
I saw this the other day on the main/larger thread but saw a couple of responses that kinda covered things. But I'll cover them here as well:
Now with all of that said. Your function at a high level makes sense for what you want to do. What's worth calling out here is when you're in a Custom Event. Log where at all possible for your own troubleshooting. Second, make sure to include a default case in your switch statement so when things don't go to plan you have a path AND event as to why. Take the following example:
But a couple of things worth pointing out in the context of the function you are in:
Your guesses are correct but $ID, $SRClass, $UserClass $AssignedToUserRelClass, and even $ServiceRequest are all already known when you are in the function
Thank you so much Adam! Exactly what I needed and very much appreciated.
I ended up with this which seems to work. However, it only works when the logging level is set to Verbose (4) lol. Anything lower and it does not seem to run or even write my debug event logs like it isn't parsing the customEvents. Might just need to upgrade SMLets which is like 3.4? Anyone have upgrade tips? I assume for the ps1 i just replace it but how do I handle the upgraded management pack without losing the config?
Anyway in case someone stumbles across this thread:
Yes, you'll need to upgrade. That was an issue that was fixed in v5.0.3. All you need to do is:
Thanks again!