26 Apr 2013

email to multiple users from SP workflow

http://go4answers.webhost4life.com/Example/send-email-multiple-users-161965.aspx


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:
  1. set workflow var:SecondaryAssigned to CurrentItem:Assigned To Secondary (formatted as a string)
  2. if workflow var:SecondaryAssigned is not empty
  3. set workflow var:SecondaryAssignedAddr to workflow var:SecondaryAssigned (formatted as email address, semicolon delimited)
  4. send email
  5. in the CC portion, select workflow var:SecondaryAssignedAddr (formatted as a string)
Hope that helps...!

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 
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
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);
}
 
 

Total Pageviews