How NOT to email end users about converted work items or how to email in SCSM 2012 using VS C#
I spent most of my last weekend to help our customer to solve the situation with notifications for affected users. Originally, the customer had set up following the notification workflows:
- If a new incident is created, send an email to an affected user with details;
- If a new service request is created, send an email to an affected user with details.
That was simple and clear. After deploying SCUtils ConvertTask that could convert incidents to service requests and vice-versa, the customer created additional notification workflows (here the video) to inform the affected users that previous incident/service request was converted to service request /incident.
Everything worked like a charm. But the customer wasn’t happy because the affected users received the first notification like ‘Your incident IR4555 has been converted to SR4556…’ and the second one like ‘The service request SR4556 has been created by your request…’. So the end user got two notifications where the latter one was obviously needless. However, if the work item was created by a regular way, that second notification was quite appropriate.
For the very beginning, the task seemed to be very easy but the customer could not use Orchestrator and I didn’t find any simple way to create a PowerShell script or workflow without extending incident and service request’s classes to send emails with the beautiful HTML templates that the customer had designed.
After several useless attempts to build a simple and use-to-use solution, I gave up and opened Visual studio. Then I closed Visual Studio and opened Bing and Google to find out the information how to send a notification programmatically in Microsoft Service Manager. Finally, I came to this blog post of Oren Beeri to whom I really appreciate. It was a first point to start and I want to share the result with the community including our beloved customers.
The solution consists of two workflows and two notification templates (for incidents and service requests). What the workflows do? First, they fire when an incident or service request is created. The second, they checks if an affected user and our custom relationship that links the initial and the resulting work items are presented. And the last, the workflows send a notification using the templates specified if the work item hasn’t been converted.
The limitations/requirements of the solution include:
- The templates have to be in HTML format;
- The email priority is always set to normal (it’s hardcoded but you have a source code to change it if required);
- Support only ‘En-US’ locate in the templates (It’s also hardcoded and can be changed in the code. In general, it might be useful to support all locates depending on the end user’s settings but that task was beyond my goal).
The notification templates I put in the solution definitely have to be edited to meet your requirements. And if you have existing notification workflows (I know you do have) for the end users about new work items, you have to disable them to avoid duplicated emails.
To deploy the solution copy NotifyIfNotConverted.dll to the Service Manager’s default folder (might be C:\Program Files\Microsoft System Center 2012\Service Manager or C:\Program Files\Microsoft System Center 2012 R2\Service Manager) on the management server (first installed one). Then import SCUtils.SendMail.Workflow.xml management pack.
The notification templates are named as Notification template for an affected user for a new service request and Notification template for an affected user for a new incident. Please feel free to customize them.
When this solution can be interested for you? If you need to send custom notifications in SCSM 2012 or if you have to check nontrivial conditions before doing something.
Or if you are a happy owner of SCUtils ConvertTask, of course :)
All the source files for Visual Studio and final files you can get using a link below.
Please try to find out what happened with the workflow "Incident - Notify affected user (custom)". You can find it in Administration -> Workflows->Status
I think it'd be better to arrange a time within the next week for the remote session, if you don't mind. Please send a proposed time to support at scutils dot com, we will set up the time.
Have you seen this video http://youtu.be/kb3z-ZxPtBs?list=UUVs3ZnyHbt3HhqiXeySs-Qg?