On the fly email notifications

January 3rd, 2008 by

A common PDMWorks Enterprise enhancement request is to give the users the ability to pick and choose who gets notified when a document goes through a workflow transition.

While personally that request seems like it would make a loophole users could use to get around the system i.e. not notifying your manager or quality control if a document is approved. -I’ll grant there may be cases where it would be useful.

So I thought I’d give you a little application that could be used to get you started in creating your own. There are fancier ways this could be done but this provides a very flexible solution and the price is right eh?

The program would be kicked off as an “action” as a document goes through a transition. [As an example see screen shot.]

Transaction

Note the full file name is sent as a command line argument using the “File Path” tag. This is how the file name gets sent to the program. Additionally, ensure the compiled .exe program is in a location where everyone has access to it.

Once started by the PDMWorks Enterprise transition, this routine simply creates a pre-populated Outlook message -populated with anything you choose. Typically the body of the message wouldn’t need to contain much -mostly just containing a link to the file that triggered the routine and some minimal instructions. The user would then, in this Outlook message, choose who to send the email to. He could also modify the body of the email if he chose. Then when the email looks as he likes he simply clicks “send”.

Here is the .NET code. Feel free to modify it to fit your needs, just keep the first comment line in! :)

Imports Microsoft.Office.Interop
Imports Microsoft.VisualBasic
Module modMain
Public Sub Main()
'by Jeff Sweeney, may he live long and prosper
Dim strFileName As String = Interaction.Command()
Dim objOutlook As Outlook.Application
Dim objNameSpace As Outlook.NameSpace
Dim objMailFolder As Outlook.MAPIFolder
Dim objMailItem As Outlook.MailItem
objOutlook = CreateObject("Outlook.application")
objNameSpace = objOutlook.GetNamespace("MAPI")
objMailFolder = objNameSpace.GetDefaultFolder(4)
objMailItem = objMailFolder.Items.Add
objMailItem.Subject = "A file needs your approval"
objMailItem.HTMLBody = strFileName & " has gone through a transition and requires you to do something"
objMailItem.Display()'gives the user a chance to modify
objMailItem = Nothing
objMailFolder = Nothing
objNameSpace = Nothing
objOutlook = Nothing
End Sub
End Module

Tip: Don’t forget you will need to add Outlook as a reference in your .NET project. Otherwise simply compile as a “Console Application” and you are set!

This is just the tip of the iceberg. You could change the routine to accept more than one parameter. An additional parameter could be the transition name, so you could get different emails depending on the transition that called it. You could have the routine examine the extension of the file and do different things depending on the file’s extension.

I’d love to learn how you end up using it!

Jeff Sweeney

CSWE Engineering Data Specialist 3DVision Technologies

7 Responses to “On the fly email notifications”

  1. Joy Garon says:

    Hi Jeff -

    Nice job! This is a very common request. Do you have a working version?

    Joy Garon

  2. Jeff Sweeney says:

    Thanks Joy! This concept just hit me a few days ago reading the SW forum. As such, this code is not yet in production (though I expect it will be soon). I actually have this exact code running on my machine and so far it is working great. It is so simple and [nearly] elegant that I think it can work for a lot of people.

  3. Christina Seay says:

    I’m having an issue with this program, and I’m hoping that you can help. It runs fine as long as it’s on my local computer. No issues.

    When I try to save the .exe file into the vault, because our vault views are on the user’s Desktop and the file path is C:\Documents and Settings\user\Desktop\etc…. it kills the program because of the space after C:\Documents

    So I tried to move the .exe to a network drive so it’s accessible to everyone, and I’m getting
    “application attempted to perform an operation not allowed by the security policy”
    And our IT dept says it’s not a security issue on their end, that it’s a problem with the program.

    Do you have ANY idea how to get around the spaces in the file path to put it in the vault ( I can’t rename “Documents and Settings” so that it doesn’t have spaces) or how to stop the security issue while it’s on a network drive?

  4. Jeff Sweeney says:

    Your IT department is blaming the program? I suppose passing blame to an innocent program that cannot defend itself is the easiest solution! [sigh]

    It is probably a .NET security issue.
    Control Panel->Administrative Tools->.NET Framework Configuration ?.?->Runtime Security Policy->Adjust Zone Security

    Out of the “box” some .NET programs will run on a local hard drive, but not over the network.

    BTW, If you put quotes around the file name, it should work even with the space.

    Didn’t I tell you not to put the vault view on the desktop! :)

  5. Christina Seay says:

    I know.. I know.. it’s bad having the view on the desktop.. lol.. blame the VAR, they told us to. ;o)

    My IT dept is still saying that they don’t have any security settings blocking the program and that it’s still something wrong with my program.

    I looked at the .NET Configuration settings and I’m not sure what I’m looking at. We have other programs on network drives that work fine, so I’m thinking it’s something dealing with the fact that it’s accessing outlook. I even used PDM’s commands for VB to get the user and then user.SendMsg to send the email, and same thing.. works if it’s on my computer, and security issue on the network. We’re not using PDM message system, we’re using Outlook, so same issue I think.

    I tried putting quotes around the filename and that didn’t work.. it’s still getting stuck on the spaces.

    For something that should be sooo simple, this is becoming very complicated.. lol

  6. Christina Seay says:

    Ha Ha… success!!

    I went in and did it is a Shell Execute command in Dispatch and it worked! It doesn’t care about spaces in the file name!

    Thank-You!!!

  7. mike sveda says:

    SP2 issues are causing us to NOT use this feature. Solidworks is working on a fix I hope. We see a HUGE delay when performing a state transition that is using the Notifications.

Leave a Reply


nine × seven =

Follow
Get every new post delivered to your inbox
Join other followers
Powered By WPFruits.com
Bear