How to send email to People or group field user

March 2nd, 2010 | Categories: Customization, SharePoint, WSS 3.0 | Tags: , ,

People/Group field in SharePoint allow us to keep adding the existing user(s) or group(s) into the document library or list item. Let’s think, I have a list where one field name i.e. Assigned To (reviewer) is type of People/Group. Objective is when I assign someone to review the list item, and then an email notification needs to be fired up to that reviewer.
In other words, you have to find that person from the UserCollection list in SharePoint and send an email to that associated person.

Now once you assign one person on this field, you will found how the SharePoint display  his/her name in the New/Edit OTB form and it is like DOMAIN\LOGINNAME. So if your domain name is SP-SERV and your name is Himadrish Laha, it will be looks like SP-SERV\Himadrish Laha.

People O rGroup Field

Below the simple code I have used to fetch the string data and it returns me something else which I found in the debugging mode “1;#SP-SERV\\kiran” (here I have added user Kiran). When I have added my name it looks like “16;#SP-SERV\\Himadrish Laha“. String represent is kind of <UserID>;#<UserLoginName>.More difficult for you to work.

People Or Group Field Value

People Or Group Field Value

My initial thought is to split the string value and use the UserID. However latter I found this is not the actual UserID associated with the user, instead of this, it is kind of index ID associated with this user in SharePoint. So, if you try to use this ID as below, I bet you will found different user in SPUser object. So the following code is incorrect to trap actual user:


string UserAccount = _ListItem["Assigned To (Reviewer)"].ToString();
int UserID;
if (UserAccount.Trim() != string.Empty)
{
UserID = Convert.ToInt32(UserAccount.Substring(0, UserAccount.IndexOf(“;”)));

SPUser _SPUser = properties.OpenWeb().Users[UserID];
string UserEmail = _SPUser.Email.ToString();
}

What we have left now is only the login display name. Here is also one drawback to trap the user. This string is Login Display Name and it is not the LoginID. So if my login id is Himadrish.Laha and my display name is Himadrish Laha, it will show me Himadrish Laha in the People filed control text box. Note the missing of the DOT (.). For people having same string in loginID as well as Login Display name shouldn’t be a problem, but for other it will make a big difference.

To resolve this issue, the following code may help you. In most of the cases, you can simply add one DOT (.) in between user’s given name and his/her family name. Inside the code, the web represent the SPWeb object. So the method is being used here is SPWeb.EnsureUser(). You need to pass user’s login id over there, and it will return you SPUser object.


string UserAccount = _ListItem["Assigned To (Reviewer)"].ToString();
string UserLogin;
string UserEmail = string.Empty;

if (UserAccount.Trim() != string.Empty)
{
UserLogin = UserAccount.Substring(UserAccount.IndexOf(“#”), (UserAccount.Length – UserAccount.IndexOf(“#”)));
UserLogin = UserLogin.Replace(“#”, “”).Replace(“;”, “”);
UserLogin = @”SP-SERV\” + UserLogin.Replace(” “,”.”);

SPUser _SPUser = web.EnsureUser(UserLogin);
UserEmail = _SPUser.Email.ToString();
_SPUser = null;
}


Kindly note, the above code may need to change according to get the login id from the login name. If in your organization the login id is something the first character of your given name i.e. H for Himadrish and then your last name i.e. Laha, then your login id would be HLAHA. So you need to change the above code and found the actual login id what it would be. Rest of the line would be same.

Hopes this will help you.

  1. January 14th, 2011 at 07:01

    Awesome informative post. Thanks for helpful article.

  2. January 14th, 2011 at 20:22

    I’ve got to write about this for a course Im taking, well related to this. This really made it easier for me , so thanks you A TON.Take care, Tony Cyganiewicz

  3. January 16th, 2011 at 03:52

    Thank you for the good writeup. It in fact was a amusement account it. Look advanced to more added agreeable from you! However, how could we communicate?

  4. January 16th, 2011 at 18:28

    Really great informative blog post here and I just wanted to comment & thank you for posting this. I’ve bookmarked youi blog and I’ll be back to read more in the future my friend! Also nice colors on the layout, it’s really easy on the eyes.

  5. January 16th, 2011 at 19:25

    When I originally commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Thanks!

  6. January 17th, 2011 at 15:07

    I think you write this blog from a different point of view on the subject, which is rather unique from most other blogs. I welcome your difficult work on it.

  7. January 18th, 2011 at 01:48

    I am not sure where you are getting your information, but great topic. I needs to spend some time learning more or understanding more. Thanks for excellent information I was looking for this information for my mission.

  8. January 18th, 2011 at 21:49

    Ernest Hemingway~ Theres nothing noble in becoming superior to your fellow males. True nobility is being superior for your former self.

  9. January 19th, 2011 at 11:11

    I used to be very happy to find this web-site.I wanted to thanks in your time for this glorious learn!! I undoubtedly having fun with every little little bit of it and I have you bookmarked to take a look at new stuff you blog post.

  10. January 20th, 2011 at 07:13

    This web site is actually really very helpful for some1 whom has been having problems with this scenario. I have looked at a bunch of resources nonetheless to no avail. I may continue reading through and learning here in the desire of in the long run get beyond this.

  11. January 20th, 2011 at 23:02

    Awesome idea I love this

  12. January 21st, 2011 at 03:45

    Hi. Thanks for this post. My cousin recommend me this site and now I’m totally agree with her. I’ve bookmarked your site and I hope you will keep on writing.

  13. January 21st, 2011 at 07:41

    Nice submit! GA can also be my greatest earning. On the other hand, it’s not a a lot.

  14. January 22nd, 2011 at 10:04

    There are some interesting points in time in this article but I don’t know if I see all of them center to heart. There is some validity but I will take hold opinion until I look into it further. Good article , thanks and we want more! Added to FeedBurner as well

  15. January 22nd, 2011 at 11:05

    You made some decent points there. I looked on the internet for the issue and found most individuals will go along with with your website.

  16. January 22nd, 2011 at 13:59

    Superb publish, I have been looking into this good recently. Fascinating to hear some a lot more information on this. Keep up the extremely operate!

  17. January 24th, 2011 at 01:13

    Good Stuff appreciate the insight, I will be back!! A~

  18. January 24th, 2011 at 04:58

    Excellent beat ! I would like to apprentice while you amend your web site, how can i subscribe for a blog website? The account helped me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright clear concept

  19. January 24th, 2011 at 10:50

    I Will have to return again when my course load lets up – nevertheless I am getting your Rss feed so i could go through your site offline. Thanks.

  20. January 24th, 2011 at 22:33

    Author of this site is really professional staff. There are wonderful ingredients.

  21. The archetypical moment I had ever seen grouping same this web place

  22. January 25th, 2011 at 12:22

    Brilliant post, thanks ever so much for your thoughts. I think I’ll be forced to implement this in future.

  23. January 25th, 2011 at 23:50

    On the praise of a person I care to this supplying. Real extraordinary.

  24. January 26th, 2011 at 00:04

    Hello, I am sorry for being offtopic but what theme do you use? did you create it yourself? I like the theme you are using. I believe I saw one similar to your blog but I dont remember .

  25. January 28th, 2011 at 08:49

    I simply had to appreciate you yet again. I do not know what I might have worked on in the absence of those aspects contributed by you on that industry. It was an absolute horrifying situation for me personally, however , witnessing your well-written form you solved that made me to leap over happiness. I am just happy for the assistance and then expect you comprehend what an amazing job you’re carrying out educating most people through your websites. I know that you have never encountered any of us.

  26. January 29th, 2011 at 11:01

    That’s incredible!

  27. January 30th, 2011 at 22:29

    You sure do know what youre talking about. Man, this blog is just great! I cant wait to read more of what youve got to say. Im really happy that I came across this when I did because I was really starting to get bored with the whole blogging scene. Youve turned me around, man!

  28. January 31st, 2011 at 16:35

    very good post, i actually love this web site, carry on itIt’s laborious to find educated people on this subject, but you sound like you realize what you’re talking about! Thanks

  29. January 31st, 2011 at 21:31

    This so nice

  30. January 31st, 2011 at 21:49

    There are certainly a couple more details to take into consideration, but thank you for sharing this information.

  31. February 1st, 2011 at 01:47

    There are certainly a couple more details to take into consideration, but thank you for sharing this information.

  32. February 1st, 2011 at 15:33

    Dear admin, thanks for providing this blog post. I found it great. Take care,

  33. February 2nd, 2011 at 00:12

    Done well! Enjoyed checking out your post because of its terrific concepts and exceptional thoughts.

  34. February 2nd, 2011 at 21:47

    Many thanks for this valuable piece of writing. I undoubtedly enjoyed dealing with it and will definitely talk about it with everyone.

  35. February 3rd, 2011 at 03:19

    Great articles and nice a website design too :)

  36. February 3rd, 2011 at 19:21

    I honestly did not think this specific issue that way. I feel that there is certainly a point in all of this. Delighted to be in a position to get involved. Wish you good luck.

  37. February 3rd, 2011 at 21:28

    I have been browsing online more than 3 hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my opinion, if all web owners and bloggers made good content as you did, the internet will be much more useful than ever before.

  38. February 3rd, 2011 at 21:32

    I actually didn’t think this specific situation that way. I feel that there may be a point in all of this. Delighted to be capable to get involved. Wish you luck.

  39. February 4th, 2011 at 03:11

    hi thanks for your posts. can i ask somethink special ? did you make your website yourself ? if you are webmastering your site i think you did a greta well job espcially on your graphics wellnes.thanks again.

  40. February 4th, 2011 at 04:40

    This is really interesting, You are a very skilled blogger. I’ve joined your rss feed and look forward to seeking more of your great post. Also, I’ve shared your website in my social networks!

  41. February 4th, 2011 at 12:34

    a very good read very good blog will be looking out for more of these blogs

  42. February 4th, 2011 at 21:06

    You sure do know what youre talking about. Man, this blog is just great! I cant wait to read more of what youve got to say. Im really happy that I came across this when I did because I was really starting to get bored with the whole blogging scene. Youve turned me around, man!

  43. February 5th, 2011 at 01:17

    Good luck getting people behind this one. Though you make some VERY fascinating points, youre going to have to do more than bring up a few things that may be different than what weve already heard. What are trying to say here? What do you want us to think? It seems like you cant really get behind a unique thought. Anyway, thats just my opinion.

  44. February 6th, 2011 at 05:22

    Keep working ,great job!

  45. February 6th, 2011 at 05:58

    Great article…

  46. February 7th, 2011 at 02:56

    some genuinely quality blog posts on this internet site , saved to favorites .

  47. February 7th, 2011 at 04:39

    I reckon something genuinely interesting about your site so I saved to my bookmarks .

  48. February 7th, 2011 at 20:23

    actually appreciated the article that you have written actually. it really isn’t that easy to find good text toactually read (you know.. really READ and not just browsing through it like a zombie before moving on), so cheers man for not wasting my time! :D

  49. February 10th, 2011 at 17:05

    Thanks for taking the time to talk about this, I feel fervently about this and I take pleasure in learning about this topic. Please, as you gain information, please update this blog with more information. I have found it very useful. There have to be charging stations everywhere.

  50. February 10th, 2011 at 22:07

    Dear admin, thanks for providing this blog post. I found it great. Take care,

Comment pages

2 trackbacks

  1. office 2012 Trackback | 2011/04/22
  2. Scarlet Horizon Trackback | 2011/11/20
You must be logged in to post a comment.