I'm querying a SPList
and I'm retrieving a Person or Group
field object.
I want to get the DisplayName
and Email
properties but I don't know how to get them. Getters "get_email()
" and "get_displayName()
" throw error in console: "Unsupported object property or method"
I just have the Person or Group
object by storing it in a variable directly from a SPList
:
var person = found.get_item( "Assigned
" );
How to get person.get_displayName()
?
I'm querying a SPList
and I'm retrieving a Person or Group
field object.
I want to get the DisplayName
and Email
properties but I don't know how to get them. Getters "get_email()
" and "get_displayName()
" throw error in console: "Unsupported object property or method"
I just have the Person or Group
object by storing it in a variable directly from a SPList
:
var person = found.get_item( "Assigned
" );
How to get person.get_displayName()
?
- check this, you cant directly get the user details, you will have to get using the userid sharepoint.stackexchange./questions/176319/… – Guruparan Giritharan Commented Mar 22, 2018 at 7:14
1 Answer
Reset to default 4We can use fieldValue.get_lookupValue() to get the user's display name. To get more information of the user we can use the web.ensureUser() method.
The code below for your reference:
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getItemFromList, "sp.js");
function getItemFromList(){
var clientContext = new SP.ClientContext();
var item = clientContext.get_web().get_lists().getByTitle("MyTasks").getItemById(1);
clientContext.load(item);
clientContext.executeQueryAsync(
function(){
// successfully retrieved value from list item
var assigned = item.get_item("AssignedTo");
if(assigned.length>0){
var user = clientContext.get_web().ensureUser(assigned[0].get_lookupValue());
clientContext.load(user);
clientContext.executeQueryAsync(
function(){
// successfully ensured user from user name
var email = user.get_email();
var login = user.get_loginName();
var displayName = user.get_title();
alert("User LoginName: " + login + "\nUser Email: " + email + "\nUser Display Name: " + displayName);
},function(sender,args){ // on error
alert(args.get_message());
}
);
}
},
function(sender,args){ // on error
alert(args.get_message());
}
);
}
</script>
In SharePoint 2013, I suggest you use REST API with jQuery Ajax to achieve it. Check the article below:
SharePoint 2013: Get User Details from Person or Group field using REST API
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744209259a4563255.html
评论列表(0条)