I have developed a state machine workflow that is curretly working fine. Although this is working, users are complaining about being bombarded with workflow task emails that don't have anything to do with their teams. Within the doc lib I am executing the workflow, there is a column which list applications each team works on. Is there a way to get the information from this field and route to the correct group. This will be dynamic so the column value may change. The column is a drop-down field (which you cannot retrieve information from...as least I think), but I have created a calculated field to retrieve the information from drop-down so it will be in a static column. In addition, I created an external List with 3 columns to try to read from as well: Group, System, and Approvers.

I.E If user picks "Computer" out of a "System" drop-down list, everyone in Approval Group "My Computer App" should get an email based off having the string "Computer" in the field and group name, then the same goes for the other choices as well with the correct groups.

A less than optimal way with huge if-else statements I'm sure is possible....trying to make it a little more dynamic and not as hard-coded..

if (Listitem = system
createTask_taskProperties.AssignedTo = "IT Group A"
e.Result = true;
if (Listitem = system 2......


I am able to return the list and I can now retrieve items based upon the item ID like so

SPListItem item = list.GetItemById(26);

I need to find a way to get all values for the column/field when the workflow is triggered so I am able to pass that information to a variable. Once this is done, I should be able to call that variable in my CAML Query to determine where each item task needs to be routed. I thought I got the GUID from the column, but it was only the GUId for the list itself using this code

SPListItem item2 = list.GetItemByUniqueId[new Guid("de417a82-f221-46bd-8003-034ea45de155")];
  • the workflow is triggered automatically when an item is added or is triggered manually ? Jul 9, 2012 at 13:26
  • It is triggered automatically
    – nholloway4
    Jul 9, 2012 at 13:32
  • Since the workflow is automatically triggered, you can add an event Handler for the Workflow_Initiated event, where in you can get the desired list object and its column and set a global workflow variable and use that variable in your mail sending step. Jul 9, 2012 at 13:40
  • okay, I got you up until the gloal workflow variable. How will it route to the correct SharePoint Group.
    – nholloway4
    Jul 9, 2012 at 16:39
  • based on that variable variable, you can decide where to send mail. for this to be configurable you can make another new list in SP, which contains appropriate mail group name for each dropdown value, so you can change the target group email later on. Jul 10, 2012 at 7:34

1 Answer 1


Your query returns an SPListItem, however you need an SPGroup to retrieve the distribution list email.

To get to the SPGroup object that actually represents the Group itself rather than the name of the Group like you are returning from the List, you need to pull it from an SPWeb (which will be a little trickier since a workflow does not run in the context of a page; I'll leave this to you to figure out).

SPListItem item = list.GetItemById(26); // <-- This is your code here
string strGroupName = item["ColumnWithGroupName"].ToString();

// Get your SPWeb object from which to pull the group here
using (SPWeb webYourWeb = ...)
    // (Use SiteGroups or Groups here depending on where you want to pull the group from)
    SPGroup group = webYourWeb.SiteGroups[strGroupName];
    string strGroupEmail = group.DistributionGroupEmail;

    // Send your email

That's how you get the email address of a group from the group name (which you got from an SPListItem)

  • hmmm, I think I tried some of this last night. Seems that we dont have distribution list email setup with all the groups. When I created the SharePoint Groups I assumed that the individuals put into the group from "People and Groups" will be able to receive them. After looking in the XML and returning DistributionGroupEmail it was blank.
    – nholloway4
    Jul 31, 2012 at 13:34
  • Got it working RJ! The way you suggested will work, but only if I am a Domain Admin and have access to AD. Figured out another way to get it working. Ping me and I'll let you know. Thanks man!!!!
    – nholloway4
    Aug 12, 2012 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.