<script src="/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="/jquery.SPServices-2014.02.min.js" type="text/javascript"></script>
<script type="text/javascript">
(function () {
var ctx = {};
ctx.Templates = {};
ctx.Templates.Fields = {
Field Display Name': {
'NewForm': renderAssignedTo
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();
function renderAssignedTo(ctx) {
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 a 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: ""
};
}
</script>
<script src="/jquery.SPServices-2014.02.min.js" type="text/javascript"></script>
<script type="text/javascript">
(function () {
var ctx = {};
ctx.Templates = {};
ctx.Templates.Fields = {
Field Display Name': {
'NewForm': renderAssignedTo
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();
function renderAssignedTo(ctx) {
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 a 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: ""
};
}
</script>
No comments:
Post a Comment