Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I've got a problem with not being able to select a single list item from the User Information List, I have used U2U CAMLbuilder to build a query that extracts an entry with the ID = 1 When run in the CAMLbuilder the query returns a single valid item. But when the query is executed in javascript client object model code it returns: "all available users". This is unacceptable performance-wise.

The query itself seems to be correct, as I've said I've verified it in CAMLbuilder and also had it reviewed by a colleague. So I'm wondering if there might be any known issues with selecting items from the User Information List.

share|improve this question
add comment

2 Answers

You should be able to just use:

SPList list = SPContext.Current.Web.SiteUserInfoList;
SPListItem item = list.GetItemById(SPContext.Current.Web.CurrentUser.ID);
share|improve this answer
add comment

I think your query must be correct but you might be calling it in a wrong way. See my answer here for the correct form of using the caml query with the client object model.

no sorting with JavaScript Client Object Model?

Also, if you have to get only 1 user by ID, then you won't require the CAML query. You can use the code Jasper has provided. Only thing is that code is from the .NET managed client object model. The code in the javascript client object model will be similar to this:

var clientContext = new SP.ClientContext.get_current();

var web = clientContext.get_web();

var userInfoList = web.get_siteUserInfoList();

this.itemUser = userInfoList.getItemById(1);

clientContext.load(itemUser);

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed));


function onQuerySucceeded(sender, args)
{
    alert(itemUser.get_item("Title"));
}
function onQueryFailed(sender, args)
{
    alert(args.get_message());
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.