TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Shail S
NA
455
76.2k
Sharepoint Online- New List Form(Modern/New experience)
May 29 2018 7:38 AM
Hi,
I have a custom list created in sharepoint online. I am using the new experience for the list forms. I would want to auto-populate the current user's name in one of the people picker controls on the newlist form. The script i am using works fine in the newlist form when i use it in the classic mode. I have used a script editor to run the js which populates the current user.
How can i use this script in the newform.aspx for new/modern experience mode?
The js code to get the current user-
$(document).ready(
function
() {
$(
"input[title='RequestDays']"
).attr(
"readonly"
,
"true"
).css(
'background-color'
,
'#F6F6F6'
);
var
userid = _spPageContextInfo.userId;
function
GetCurrentUser() {
//var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
var
requestUri = _spPageContextInfo.webAbsoluteUrl +
"/_api/SP.UserProfiles.PeopleManager/GetMyProperties/"
;
var
requestHeaders = {
"accept"
:
"application/json;odata=verbose"
};
$.ajax({
url : requestUri,
contentType :
"application/json;odata=verbose"
,
headers : requestHeaders,
success : onSuccess,
error : onError
});
}
function
onSuccess(data, request){
//var loginName = data.d.Title;
console.log(data);
var
loginName = data.d.DisplayName;
var
myManager = data.d.UserProfileProperties.results[15].Value;
SetUserFieldValue(
"Requestor"
,loginName);
SetUserFieldValue(
"Approver"
,myManager);
}
function
onError(error) {
//alert(error);
}
function
SetUserFieldValue(fieldName, userName) {
var
_PeoplePicker = $(
"div[title='"
+ fieldName +
"']"
);
var
_PeoplePickerTopId = _PeoplePicker.attr(
'id'
);
var
_PeoplePickerEditer = $(
"input[title='"
+ fieldName +
"']"
);
_PeoplePickerEditer.val(userName);
var
_PeoplePickerOject = SPClientPeoplePicker.SPClientPeoplePickerDict[_PeoplePickerTopId];
_PeoplePickerOject.AddUnresolvedUserFromEditor(
true
);
}
GetCurrentUser();
});
How am i supposed to inject this js into the newform.aspx for the list?
Please advice...
Reply
Answers (
10
)
Event Receiver on Custom List
Get-PnPGroupPermission is not working