Get current login user in SharePoint using JQuery

Advertisement
In this article we can able to know, how to populate current login user in SharePoint and we can able to populate in to people picker using JQuery.
First upload the JQuery in to the Site Assets library.

Navigate to particular list that you want to populate the current login user ,In the NewForm.aspx edit the page add the current editor edit it  and refer the JQuery file.

<script type="text/javascript" src="/sites/dotnetsharepoint/SiteAssets/jquery.SPServices-0.7.2.min.js"></script>
<script type="text/javascript" src="/sites/dotnetsharepoint/SiteAssets/jquery.SPServices-2014.02.min.js"></script>

<script language="javascript" type="text/javascript">
$(document).ready(function()
{
ExecuteOrDelayUntilScriptLoaded(populateCurrentUser, "sp.js");
});

function populateCurrentUser() {
var currentuserName = $().SPServices.SPGetCurrentUser({
fieldName: "UserName",
debug: false
});

var controlName = "Author"; // fieldname in the list
var peoplepickerDiv = $("[id$='ClientPeoplePicker'][title='" + controlName + "']");
var peoplepickerEditor = peoplepickerDiv.find("[title='" + controlName + "']");
var sppeoplepicker = SPClientPeoplePicker.SPClientPeoplePickerDict[peoplepickerDiv[0].id];
peoplepickerEditor.val(currentuserName);
sppeoplepicker.AddUnresolvedUserFromEditor(true);
}
</script>


SharePoint Online Real Time Training Contact: JLAKSHMITULASI@GMAIL.COM
Advertisements
SHARE

Unknown

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a comment