http://go4answers.webhost4life.com/Example/send-email-multiple-users-161965.aspx
26 Apr 2013
How to insert multiple person/group field contents into CC portion of workflow email
Issue: You want to be able to pull the values
contained in a multiple person/group field in a SharePoint list into a
workflow, and insert them into the CC portion of the send email workflow
action.
A most brilliant colleague of mine was able to find a quick and easy workaround for this pesky issue.
In this scenario, the users to be CC'd are contained in a multiple person/group field in the list that the workflow is running on, called 'Assigned To Secondary'
To solve the problem:
http://geekswithblogs.net/DinoGrl/archive/2012/04/24/sharepoint-2010-how-to-insert-multiple-persongroup-field-contents-into.aspx
A most brilliant colleague of mine was able to find a quick and easy workaround for this pesky issue.
In this scenario, the users to be CC'd are contained in a multiple person/group field in the list that the workflow is running on, called 'Assigned To Secondary'
To solve the problem:
- set workflow var:SecondaryAssigned to CurrentItem:Assigned To Secondary (formatted as a string)
- if workflow var:SecondaryAssigned is not empty
- set workflow var:SecondaryAssignedAddr to workflow var:SecondaryAssigned (formatted as email address, semicolon delimited)
- send email
- in the CC portion, select workflow var:SecondaryAssignedAddr (formatted as a string)
http://geekswithblogs.net/DinoGrl/archive/2012/04/24/sharepoint-2010-how-to-insert-multiple-persongroup-field-contents-into.aspx
How to get SPUser or SPGroup from Person or Group field
You have person or group field in SharePoint list and you want to programmatically get the user or person.
The below code to gets SPUser from User or Group field in the list
The below code to gets SPUser from User or Group field in the list
Multiple choice X
Groups X
//get SPUser
SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");
SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["Users"].ToString());
SPUser user = userFieldValue.User;
Multiple choice Y
SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");
SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["Users"].ToString());
SPUser user = userFieldValue.User;
Multiple choice Y
Groups X
//Multiple choices are allowed
SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");
SPFieldUserValueCollection userFieldValueCollection = (SPFieldUserValueCollection)userField.GetFieldValue(item["Users"].ToString());
foreach (SPFieldUserValue userFieldValue in userFieldValueCollection)
{
Console.WriteLine(" " + userFieldValue.User.LoginName);
}
Group Y
//Group or User are allowed
SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");
SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["Users"].ToString());
//Tries to get SPUser
if (userFieldValue.User != null)
{
SPUser user = userFieldValue.User;
}
//if the field contain group
else
{
SPGroup group = web.SiteGroups.GetByID(userFieldValue.LookupId);
}
//Multiple choices are allowed
SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");
SPFieldUserValueCollection userFieldValueCollection = (SPFieldUserValueCollection)userField.GetFieldValue(item["Users"].ToString());
foreach (SPFieldUserValue userFieldValue in userFieldValueCollection)
{
Console.WriteLine(" " + userFieldValue.User.LoginName);
}
Group Y
//Group or User are allowed
SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");
SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["Users"].ToString());
//Tries to get SPUser
if (userFieldValue.User != null)
{
SPUser user = userFieldValue.User;
}
//if the field contain group
else
{
SPGroup group = web.SiteGroups.GetByID(userFieldValue.LookupId);
}
Subscribe to:
Posts (Atom)