Created
March 16, 2015 13:55
-
-
Save rheid/d845826ceb106d8ae330 to your computer and use it in GitHub Desktop.
SharePoint 2013 Set People Pick Field to CurrentUser (JQuery, SPServices)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var ctx = {}; | |
ctx.Templates = {}; | |
ctx.Templates.Fields = { | |
'Schulungsteilnehmer': { | |
'NewForm': renderAssignedTo | |
} | |
}; | |
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx); | |
})(); | |
function renderAssignedTo(ctx) { | |
//get current user properties | |
var currentUser = $().SPServices.SPGetCurrentUser({fieldNames: ["Title", "Name"]}); //get current user properties | |
var currentUserEntry = createUserEntity(currentUser.Name,currentUser.Title); | |
//Set user default value | |
ctx.CurrentFieldValue = []; //Note: it is assumed the user field is aaa multi-valued field (!) | |
ctx.CurrentFieldValue.push(currentUserEntry); | |
return SPClientPeoplePickerCSRTemplate(ctx); | |
} | |
function createUserEntity(userLoginName,userDisplayName) | |
{ | |
return { | |
Description: userLoginName, | |
DisplayText: userDisplayName, | |
EntityGroupName: "", | |
EntityType: "", | |
HierarchyIdentifier: null, | |
IsResolved: true, | |
Key: userLoginName, | |
MultipleMatches: [], | |
ProviderDisplayName: "", | |
ProviderName: "" | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment