Page 1 of 1
Get Login Name from People Picker
Posted: 27 Feb 2018
by TonyDuke
Good Morning,
I am trying to retrieve the Login Name from a People Picker Field on an Edit Form to show or hide fields based on if the current user is the user entered in the People Picker Field.
My Field is called "Responsibility" and from looking at the documentation the correct method to get the email value of the field is below
Code: Select all
var responsibility = fd.field('Responsibility').value()[0].EntityData.Email;
As you will see from the below image the above method does not work.
- Capture.PNG (12.88 KiB) Viewed 3549 times
Any help appreciated.
Thanks
Re: Get Login Name from People Picker
Posted: 27 Feb 2018
by Nikita Kurguzov
Dear Tony,
I can only assume by the returned value that you are trying to execute this code on Display Form or People Picker field is set to read-only in the designer. In all other cases, it should return an object with multiple properties, but on Display Form, it only stores the name and there is no simple way to retrieve an email.
It would be easier to retrieve an email when first saving an item or editing it, on save, and store it in another field using this JavaScript.
Then you can easily retrieve it from this field even on the Display Form.
Re: Get Login Name from People Picker
Posted: 01 Mar 2018
by TonyDuke
Hi Nikita,
Thank you for your response, for your information on further investigation it appears the issue is with that particular user "Mark Stacey", the functionality works for all other users, I can't understand why?!?
The function works on a New Form for that user but not on an edit Form.
However as you rightly say there is no way to retrieve the email address on a Display Form and we do need to apply the functionality there also, so I have now added an additional field to store the email address that is created on the New Form and Updated onChange on the Edit Form and we are using this field as the test for our function.
Thanks again.
Re: Get Login Name from People Picker
Posted: 05 May 2019
by Adam Reyes
Is it possible to get the users Office or Work Phone number from the People Picker as well? I've tried different variations of the code but can't seem to pull the phone number. I've tried using this to no avail:
var varPhone = fd.field('ContractsAdminName').value()[0].EntityData.WorkNumber;
Re: Get Login Name from People Picker
Posted: 07 May 2019
by ibarrandres
For something like this.. If Active directory has that information and its being used in conjunction with the user profile service, I would just use the
endpoint.
example of response:
Code: Select all
<?xml version="1.0" encoding="utf-8"?><entry xml:base="https://webapplication.com/sites/sitecollection/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>https://webapplication/sites/sitecollection/_api/Web/GetUserById(1)</id><category term="SP.User" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/GetUserById(1)" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Groups" type="application/atom+xml;type=feed" title="Groups" href="Web/GetUserById(1)/Groups" /><title /><updated>2019-05-07T03:06:25Z</updated><author><name /></author><content type="application/xml"><m:properties><d:Id m:type="Edm.Int32">1</d:Id><d:IsHiddenInUI m:type="Edm.Boolean">false</d:IsHiddenInUI><d:LoginName>i:0#.w|domain\firstname.lastname</d:LoginName><d:Title>Andres Ibarra</d:Title><d:PrincipalType m:type="Edm.Int32">1</d:PrincipalType><d:Email></d:Email><d:IsShareByEmailGuestUser m:type="Edm.Boolean">false</d:IsShareByEmailGuestUser><d:IsSiteAdmin m:type="Edm.Boolean">true</d:IsSiteAdmin><d:UserId m:type="SP.UserIdInfo"><d:NameId>s-1-5-21-773101994-1372423740-560890886-11372</d:NameId><d:NameIdIssuer>urn:office:idp:activedirectory</d:NameIdIssuer></d:UserId></m:properties></content></entry>
OR
Code: Select all
https://webapplication/sites/sitecollection/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='NamePropertyfromAD')?@v=%27accountname%27
Example of response:
Code: Select all
<d:GetUserProfilePropertyFor xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">Andres</d:GetUserProfilePropertyFor>
For the first endpoint...watch for the json response and grab the value needed then pass that to the field. The second specifies which property to return so you will only have one value to look for.