Question

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;
}
else
{
if (Listitem = system 2......

UPDATE

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")];
Was it helpful?

Solution

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top