18.09.2011 I have posted a new solution to this “problem”. I recommend you use the new one. You find it here
I got this request from Indra:
This is really great blog!! awesome work and i am big fan of this site, i check everyday and look at the things and learn , but i need something that i cannot find any where. Let me explain what i need..
I have a list with a people picker and a field called email address, i want to get the email address populated automatically depending the person on people picker ( single user). I know that i need to get user information from profile, but i am not a programmer and there i need your help.
I know you are really busy but please spotlight when you have time.
Thanks in Advance.
This code fills the e-mail address when the item is saved. It pulls the email address from a “resolved” user in a people picker, and writes it to a separate text field.
As always we start like this:
The jQuery-library is found here. The pictures and the sourcecode refers to jquery-1.4.min. If you use another version, please update the reference in the code.
The scripts “interaction.js” and “stringBuffer.js” is created by Erucy and published on CodePlex.
Read here how to add a CEWP to NewForm or EditForm, and how to get the guid for a list.
Add this code to a CEWP below the NewForm or EditForm:
You must change these four parameters in the script:
- userListGuid: The listGuid of the user list
- userListBaseUrl: The base URL for the userList. Most likely an empty string “”, but If the site resides on a managed path, this must be reflected.
- myPeoplePickerFin: FieldInternalName for the people picker
- myTextFieldFin: FieldInternalName for the single line text field to hold the email address
Ask if anything is unclear.
23 thoughts on “Pull e-mail from people picker and write to a separate textfield”
I’m getting a fields is undefined error. Any ideas?
Check line 5 in the script above.
Read more here: How to troubleshoot when the scripts does not work
Actually I was using jquery-1.4.2.min.js. That was the undefined error.
However I’m having trouble getting this to work. When debugging in IE I noticed that the length of the PeoplePicker field is always 0 so I don’t execute the if(myPeoplePicker.length>0) logic in the PreSaveAction() function.
Any idea why would my pp length is always 0? My parameters are setup up this way:
userListGuid = ‘0BC378E4-61EF-4F1D-86DD-9DE9D64D4A59’;
userListBaseUrl = ‘http://portalesdevsrv/development/sites/directoriotelefonico’;
myPeoplePickerFin = ‘Nombre_’;
myTextFieldFin = ‘Titulo’;
Ensure that the CEWP is placed below the form, and that your FieldInternalName of the people picker is correct.
Yes. That was it. I had the CEWP above the form. Finally making progress. Thanks!
Now… no matter what user I select I get the following written to my text field: User with id domainusername not found. Profile services seem to be working fine.
Are your site collection in a managed path? if so, you must modify the parameter”userListBaseUrl” to reflect this.
Yes, my site collection is on a managed path. Can you provide an example for the user list base url parameter? Thanks.
userListBaseUrl = “/ThisIsTheManagedPath”;
What if I have a site collection under the managed path and a subsite under the site collection?
Should I say:
userListBaseUrl = “/ThisIsTheManagedPath/SiteCollectionName/SubSiteName”;
I tried this but didn’t work.
The “People and groups” list is located at the root of your site collection. Any subsite must refer this list from the root.
Go to the root of your site collection > go to the “People and groups” list > right click > view source > search for L_Menu_BaseUrl.
The value for L_Menu_BaseUrl is your managed path “root”.
This worked perfectly! Thanks!
Small issue I found:
Some users get validated in the people picker but still get error:
User with id domainusername not found in the text field.
I found that these users weren’t added directly to the user list, instead they got access because of the domain users group. Is this the expected behavior? Any workarounds to avoid the need to add each user to the list (I have about 4000 users for that site)?
Does this happen with users that have not yet logged in to the SharePoint site?
I have not tested it, but i would think that could be the issue. If so, i have no fix for it as the information is pulled from the “user list” in the SharePoint site, and this is not populated before the user logs in the first time.
userListGuid = ‘046EA598-CBA3-47C7-BA53-29120ED4033E’;
userListBaseUrl = ‘/gscticketing’;
myPeoplePickerFin = ‘RequestorName’;
myTextFieldFin = ‘RequestorEmail’;
I have my page as: http://intraneturl:82/gscticketing/default_ERIC_AD_w_lookup.aspx
My page uses a data view web part.
Nothing happens when I edit the requestor name and check the name.
My fields were renamed to Requestor Name and Requestor Email, but the internal name is still RequestorName and RequestorEmail.
The guid I am using is from the Members list of my site.
If you use a modified form, you must take a look at this article: How to use these scripts in a customized form
I tried using the code even on a standard EditForm.aspx page, but no luck. Does this work on SP 2007 SP2 MOSS?
Does the site reside in a managed path? If so, check the “userListBaseUrl”
Still wont work. I checked my base URL and it is /gscticketing, I tried it without as well. I am using a CEWP below my default edit form using the browser only and not SPD.
My GUID is pointing to the Members Permissions Group list of my site. My field names are internal and were changed to Requestor Email and Requestor Name, with spaces, but the interanal names are RequestorEmail and RequestorName.
I am a site collection administrator. I can see the list. My name is in the list. I fill in my name as requestor name and it does not populate my email below.
Not sure if this is relevant, but you know that the email is pulled when the item is saved (pressing the OK button) and not when the name is resolved by pressing the “Resolve button”?
Is it possible to make this code fire on the onChange event of the people picker field instead of on write of new item?
I need exactly what you have done but it has to fire in the UI not on save. Can this code be tweaked to run in the UI. For example, after the person is selected from the people picker, and onchange event or listnered would fire and pre populate the new.aspx form. I need this for the OOTB contacts list.
How would you change the above code to have the myTextFieldFin field updated with the email not at item’s save, but at each people picker change [ event .change() ] ?
I tried numerous possibilities with no success.
Hi Eric, DMB and Marc,
I have posted a new solution here