SharePoint Development Bookmark and Share   
 index > SharePoint - Workflow > Workflows, e-mails and people fields
 

Workflows, e-mails and people fields

Hi,

I have a workflow that I intend to use to have managers authorise purchases. I'm using Sharepoint Designer and Sharepoint Services 3.0

The initial list has several fields but in particular it has a field called "Requested By" and "End User".

These fields will detail who requested the order and who will use the product we are ordering.

The first stage in my workflow should send an e-mail to these users outlining the procedure.

Here's the problem:

If i set these two fields as Single Line of Text, then when it sends the e-mail it cannot resolve "Joe Bloggs" to an email address - obviously the workflow isn't able to look up against AD. (I know this as I copied the team secretary in the email, hardcoded in the workflow

If I set it as a person field it sends the e-mail correctly, but I also want to use these fields in the e-mail, but it inserts them as domain\username instead of the person's actual name.

Can anyone make any suggestions as to how I would achieve this?

Regards

Harkernator  Wednesday, May 09, 2007 1:17 PM

Hi,

Does anyone have any suggestions??

Regards

Harkernator  Tuesday, June 05, 2007 4:06 PM
I've posted about the same issue about a month ago and got no response so far. I haven't been able to find any info about this. Anyone know how to do this?
MoniM  Monday, June 11, 2007 9:32 PM
I ran into this same issue, and searched high and low for an answer. I came across this link which pointed me in the right direction:

http://www.sharepoint-tips.com/2006_06_01_archive.htmlScroll down to Tuesday June 27th 2006. The code example there uses the ParentWeb.Users collection. I could not get that working, so I used the AllUsers collection, and that did work.

I have since created a custom action that does a lookup based on the email.

The code looks something like this:

Code Snippet

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{

SPSite site = __Context.Site;

SPWeb web = __Context.Web;

string errorString = "empty.";

bool allowit = web.AllowUnsafeUpdates;

try

{

// Do nothing if the field value to assign is empty.

if (this.FieldValue != "")

{

//Assign the guid for the list.

errorString = "Workflow error: Assigning GUID " + this.List;

this.List.Trim();

this.List.ToLower();

Guid listGUID = new Guid(this.List);

//Get the list object

errorString = "Workflow error: Assigning List " + this.List;

SPList list = web.Lists[listGUID];

//Get the item within the list

errorString = "Workflow error: Assigning List Item " + Convert.ToString(this.Item);

SPListItem item = list.GetItemById(this.Item);

//Check for lookup by email

this.FieldValue.Trim();

errorString = "Workflow error: Checking for @ in " + this.FieldValue;

if (this.FieldValue.Contains("@"))

{

errorString = "Workflow error: New variable user.";

SPUser user;

//Get the user by the email address passed

errorString = "Workflow error: Get user for this email address: " + this.FieldValue;

user = web.AllUsers.GetByEmail(this.FieldValue);

//Assign the user.

errorString = "Workflow error: Checking for no user returned using email.";

if (user != null)

{

web.AllowUnsafeUpdates = true;

errorString = "Assigning user to field after email lookup: field-" + this.FieldToUpdate +

" Name-" + Convert.ToString(user.Name) + " EMail-" + user.Email;

item[this.FieldToUpdate] = user;

item.UpdateOverwriteVersion();

web.AllowUnsafeUpdates = allowit;

}

else

throw new Exception("Workflow error: user returned is null " + this.FieldValue);

}

else

{

//Assign the name from the field passed

errorString = "Getting particular user from name.";

string[] domainName = new string[1];

domainName[0] = this.FieldValue;

errorString = "Workflow error: New variable user.";

SPUser user;

//Assign the user from the user collection

errorString = "Workflow error: Assigning user from get collection.";

user = web.AllUsers.GetCollection(domainName)[0];

//Assign the user

errorString = "Workflow error: Checking for no user returned using name.";

if (user != null)

{

web.AllowUnsafeUpdates = true;

errorString = "Assigning user to field after name lookup: " + this.FieldToUpdate +

" " + Convert.ToString(user.Name);

item[this.FieldToUpdate] = user;

item.UpdateOverwriteVersion();

web.AllowUnsafeUpdates = allowit;

}

else

{

throw new Exception("Workflow error: Didn't find user by name for " + this.FieldValue);

}

}

}

}

catch (Exception e)

{

//Uncomment the following line to log errors

//throw new Exception("Workflow error: " + errorString + " *****" + e.Message + " *****");

}

finally

{

//Get rid of the resources

web.Close();

web.Dispose();

site.Close();

site.Dispose();

}

//Return execution status

return ActivityExecutionStatus.Closed;

}

I had to use the UpdateOverwriteVersion method to avoid creating several hundred versions (apparently one for each field in the list) as I have versioning turned on for the list where I am using this. Some of the code is superfluous but after I finally got it working, I needed to move on, and it is not really hurting anything being in there.

I have not actually tried using this to update from an account name, but I know the email assignment works.

Hope this helps.

Tom

Tom Atchison  Tuesday, June 12, 2007 3:51 PM

Hi Tom,

Thanks for the information, I guess the problem im having is that im still trying to understand the development enviroment. The code that you posted where would that be inserted, are you using share point designer or VS2005 using the workflow plugin?

Any insight that you can supply would be great.

Thanks

David of Chicago  Thursday, June 14, 2007 1:42 PM

The code is part of a custom activity created for use in SharePoint Designer (essentially a class created and deployed to the gac). Once the activity is created, you can use it in any workflow created using SharePoint Designer.

There a numerous sources describing this process. One source should be the SharePoint Server SDK. Here are some links to some further information:

http://www.johnholliday.net/archive/2007/03/27/Add-Your-Own-Custom-Workflow-Activities-to-SharePoint-Designer-2007.aspx

http://www.codeproject.com/useritems/CustomActivity.asp

http://glorix.blogspot.com/2007/03/spd-workflow-activity-copying-listitem.html

Tom

Tom Atchison  Friday, June 15, 2007 3:09 PM

You can use google to search for other answers

Custom Search

More Threads

• HTTP 403 Forbidden: ASPX Task Form
• Possible to create a secondary workflow that modifies tasks created by a primary workflow?
• How to update a Document from a secondary Task WF
• My workflow with action pause for duration 1 minute created in sharepoint designer 2007 never terminates
• Urgent Help Required for Workflow Foudantion
• copy field from one list to another one with workflow
• Creating folder items in SharePoint using VS 2005 workflow
• Where are my out-of-the-box workflows?
• Workflow Properties from Code
• Designer Workflow Failed on start document library new upload