In my Office 365 (SharePoint Online) I have a very simple Custom List which consists of a bunch of columns/fields, and I have a requirement that when a user clicks on: Add New Item, The logged user's name or email address will be populated into a PeoplePicker field (EmployeeName), and the logged user's phone number will be populated into another SingleLineText field called (EmployeePhone). Other fields will be filled manually by the user.

How can I accomplish this? Could you please share with me some code/scripts?

enter image description here

For getting the user\s email address and populating it into a PeoplePicker field (EmployeeName) I have used the script below. But, I am not happy with it as it only works with IE, But, NOT other browsers.

<script type="text/javascript">
    $(document).ready(function () {
        ExecuteOrDelayUntilScriptLoaded(setLoginName, "clientpeoplepicker.js");

    function setLoginName() {
        var loginName = _spPageContextInfo.userLoginName;
        var peoplePickerDiv = $("[id$='ClientPeoplePicker'][title='EmployeeName']");
        var peoplePickerEditor = peoplePickerDiv.find("[title='EmployeeName']");
        var spPeoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[peoplePickerDiv[0].id];

I would really appreciate if you could help me to get these two values from user's profile, Delve, or anywhere as long as the code is something I can put inside a Script Editor web part.

Thank you very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.