Can't get login name from People field
Posted: 08 Feb 2018
I struggle to get login name from a single value people field into a variable using js.
Here are a number of alternatives that I've tried, but none of them return anything.
// Alternative 1
var ansatt = fd.field('Ansatt').value().dictionaryEntries[0].AccountName;
// Alternative 2
var ansatt = fd.field('Ansatt').value()[0].DisplayText;
// Alternative 3
fd.field('Ansatt').control('ready', function() {
alert(fd.field('Ansatt').value()[0].DisplayText);
});
// Alternative 4
fd.field('Ansatt').control('ready', function() {
var selectedUsers = fd.field('Ansatt').value();
for (var i = 0; i < selectedUsers.length; i++) {
alert('Login: ' + selectedUsers.Key);
}
});
This one works, but returns the user display name
var ansatt = fd.field('Ansatt').value();
I need to get the login info in order to decide if this is current user or not.
(var currentuser = user.get_loginName();)
Any help on how to build the code to pull login info from a people field is appreciated.
Thanks
NB! This is SharePoint Online.
Here are a number of alternatives that I've tried, but none of them return anything.
// Alternative 1
var ansatt = fd.field('Ansatt').value().dictionaryEntries[0].AccountName;
// Alternative 2
var ansatt = fd.field('Ansatt').value()[0].DisplayText;
// Alternative 3
fd.field('Ansatt').control('ready', function() {
alert(fd.field('Ansatt').value()[0].DisplayText);
});
// Alternative 4
fd.field('Ansatt').control('ready', function() {
var selectedUsers = fd.field('Ansatt').value();
for (var i = 0; i < selectedUsers.length; i++) {
alert('Login: ' + selectedUsers.Key);
}
});
This one works, but returns the user display name
var ansatt = fd.field('Ansatt').value();
I need to get the login info in order to decide if this is current user or not.
(var currentuser = user.get_loginName();)
Any help on how to build the code to pull login info from a people field is appreciated.
Thanks
NB! This is SharePoint Online.