function getSiteUsers()
{
var call=jQuery.ajax({
url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/siteusers",
type:"GET",
dataType: "json",
headers: {
Accept: "application/json;odata=verbose"
}
});
call.done(function(data,textStatus,jqXHR){
var users=data.d.results;
var usrs=[];
for(var i=0;i<users.length;i++)
{
if(users[i].UserId!=null&&users[i].LoginName.indexOf("onmicrosoft.com")!=-1)
{
usrs.push(users[i].Title);
}
}
$( "#email" ).autocomplete
({
/*Source refers to the list of fruits that are available in the auto complete list. */
source:usrs,
/* auto focus true means, the first item in the auto complete list is selected by default. therefore when the user hits enter,
it will be loaded in the textbox */
autoFocus: true ,
});
});
call.fail(function(jqXHR,textStatus,errorThrown){
var response=JSON.parse(jqXHR.responseText);
var msg=response ? response.error.message.value : "Error";
alert("Call Failed:"+msg);
});
}
<input type="text" id="email" name="email"/>
- _spPageContextInfo.webAbsoluteUrl+"/_api/web/siteusers" url gives you all site users along. Say for example My sharepoint site has only one user i.e "Madhumati Hosamani" along with this users there are some existing site users will be returned.
- [15:02:20.490] Everyone
[15:02:20.490] Everyone except external users
[15:02:20.490] madhumati hosamani
[15:02:20.490] NT AUTHORITY\authenticated users
[15:02:20.490] _SPOCacheFull
[15:02:20.490] _SPOCacheRead
[15:02:20.490] System Account
[15:02:20.490] YLO001\_spocrwl_337_16600
- To filter and get only site use, I have used following logic
This checks that UserID should not be null which is null in case of ['Everyone', 'Everyone except external users' and 'NT AUTHORITY\authenticated users'] and site user login name ends with onmicrosoft.com.
- To set it to autocomplete of text box use following snippet:
- $( "#email" ).autocomplete
({
/*Source refers to the list of fruits that are available in the auto complete list. */
source:usrs,
/* auto focus true means, the first item in the auto complete list is selected by default. therefore when the user hits enter,
it will be loaded in the textbox */
autoFocus: true ,
});
No comments:
Post a Comment