This project has moved and is read-only. For the latest updates, please go here.

GetUserInfo for other users

May 24, 2011 at 9:11 PM


 I am using below code to get the user ID, name from other site as I need to duplicate the list entry on different sitecollection:

    operation: "GetUserInfo", 
    async: false, 
    webURL: "http://DestinationSiteCollectionURL", 
    userLoginName: user, 
    completefunc: function (xData, Status) { 
        $(xData.responseXML).find("User").each(function() { 
            curUserId = $(this).attr("ID"); 
            curUserName = $(this).attr("Name"); 
            curFullUserName = $(this).attr("ID")+";#"+$(this).attr("Name"); 

So for example: if user exists at the destination site then it will work fine and I will get the result in curFullUserName.

But problem occurs when user does not exists at the destination site. I am getting an error "curFullUserName is undefined" so my question: Is there any function that check the user and if user doesnt exists then add it ??   OR    How can I check whether i got result before running 'completefunc' and then can i add that user to destination using 'updatelistitems' ??

May 24, 2011 at 9:14 PM

Can't you just check to see if the result is empty and branch accordingly?


May 24, 2011 at 9:21 PM
Edited May 24, 2011 at 9:22 PM

I dont know how to. I am still new in jQuery.

Before executing whats inside the completefunc, I want to check whether there is any result like :

if ( xData == 'null')  or   (Status == 'success')  but doesnt seem to work. So I guess i m missing something.

Also, what is the best way to add user to 'User Information List' ??

May 24, 2011 at 9:50 PM

I think what you are doing is sort of kludgy. Users get added to the User Information List by "touching" an object in the Site Collection. That could be anything as obvious as visiting the Site Collection to as subtle as someone else adding them to a permission group.

What's your actual goal here?


May 24, 2011 at 10:06 PM
Edited May 24, 2011 at 10:07 PM

My Goal:  When someone create a new item in List A under site A - create same item under list B under site B

Now the problem is when you enter a user in filed X under List A, that user never visited site B. so there will not be any entry under 'User Information List' for that person - which is exactly what i need while create the item under List B with that user name.

May 24, 2011 at 10:08 PM

Sounds even more kludgy. Why are you creating the duplicate items? Getting to the bottom of the actual business requirements can often expose a simpler approach.


May 24, 2011 at 10:12 PM
Edited May 24, 2011 at 10:12 PM

Dept ABC has subdept XYZ. Both maintain their own list and already published the url. 

So now manager doesnt like to go to both lists so they asked me to create the duplicate entry of XYZ under ABC in realtime and automated.

May 24, 2011 at 10:16 PM

Ick. That's definitely kludgy. How are you going to keep those two items in synch? Or doesn't it matter?

Regardless, how about creating a dummy SharePoint Group in the destination Site Collection and adding the user to it? That ought to put them into the User Information List. I wouldn't try to edit the User Information List directly. It might be fine, but I would be worried about side effects.


May 24, 2011 at 10:21 PM
Edited May 24, 2011 at 10:21 PM

No need to keep in sync. And later on even if needed, I can do the same on the editform using updatelistitem.

I havn't tried using the dummy group. But what credential will be used when someone create a new item in List A and i make a call for webservice from newform.aspx - they might not have permission for site B. 

List A is open to all user to take their request. List B is for high level people only.


Also, Let me know if you think there is any better way then using spservices. I thought this is the best.

May 24, 2011 at 10:24 PM

Hmm. If you want everyone who has access to Site A to be able to create items in Site B, then you have a permission conundrum. Web Services calls operate under the current user's credentials and there's no way to elevate permissions.

If you think about that for even second or two, you'll see the logic in it.


May 24, 2011 at 10:36 PM
Edited May 24, 2011 at 10:38 PM

Say I will give access to all users on both lists.  ('All authenticated user' with contribute access)

And I will create a dummy group. Still any user will NOT be able to add user to that group coz they are not member/owner of that group and I can not add all employee of the company to it (coz its 40000)

FYI... duplicate item solution is already in place and its working as far as they do not put any new user in the people picker field.

May 24, 2011 at 10:38 PM

What about a Powershell script that runs nightly, adding any new users to the group in Site B? (And maybe then removes them just to clean things up.)


May 24, 2011 at 10:38 PM

What about a Powershell script that runs nightly, adding any new users to the group in Site B? (And maybe then removes them just to clean things up.)


May 24, 2011 at 10:40 PM
Edited May 24, 2011 at 10:57 PM

Can not touch server. Only client side solution.

And even if I put it on my desktop, I have to keep it running. Not a good solution.

I am so close.. but stuck at this issue.


Does anyone used 'UpdateListItems' when the item has person field where that person never visited the site.

May 25, 2011 at 12:17 AM
Edited May 25, 2011 at 3:25 AM

Are you positive that you can't add the item copy in Site B without the user being in the User Information List?

There also might be some other kludgy tricks to match what you're trying to do, like an AJAX call to fetch the home page of Site B. That might add the user to the UIL.

This one is a little hard to test, too.


May 25, 2011 at 2:21 AM

I ran into a situation like that before.  Any user that you will need to use the People Picker for will have to be in the UIL (User Info List).  I think PowerShell is the way to go.  You don't have to touch the server to user PowerShell.  You can use PowerShell Remoting features that will allow you to run scripts from your desktop against your farm.

May 25, 2011 at 3:26 AM

Sorry; sending from my iPhone sometimes gets garbled. Corrected version above.


May 25, 2011 at 3:57 PM

If you are adding the item to the list in SPServices, or can use SPServices to copy to the second list, then I have a working solution. I just wanted to be sure that Marc would not mind me posting it because it is "Evil" but it worked for me.

May 25, 2011 at 4:27 PM
Edited May 25, 2011 at 4:27 PM

In this case, the whole thing seems evil. :-) Post away! The issue here is the separate Site Collections.


May 25, 2011 at 4:38 PM

I did want to point out that I understand as Marc stated that what you are doing is kludgy, but sometimes it is what you have to work with as I am sometimes faced with the same thing. The first part of my solution would require creating a dummy list on the second site with just a title field. Then go to the permissions for the list and give Authenticated Users contribute to the list. Then you can do the following steps that I have tested to work fine in WSS 3. 

  • When the user creates the item you want to copy, you do the normal check to see if they are in the UserInfo list of the second site.
  • If they are not in this list, in the same action, use SPServices to add an item to the list created above setting the title to "Testing" or whatever you want.
  • This will then add that user to the UserInfo list. (Remember that they are the one running the code!)
  • Now you can get that users information including their ID from the second site and add the copied values to the second list with the user.
  • Delete the item created above.

So, yes, this did work for me, and it is again not the best option, but it does work in my environment. The user running this must be an authenticated user of course! Let me know if you need some code to get you going.

May 25, 2011 at 4:45 PM


I'm not sure that you need the dummy list. I think "touching" *anything* in Site B should add the user to the UIL, right? Have you ever tried the AJAX fetch of the home page idea?


May 25, 2011 at 4:54 PM

Duh, if they have to add an item to the second list anyway, then they need add permissions to that list so you would have to have Authenticated Users on that list instead of a dummy one! They could at least have add permissions. This would shorten the steps you would need to take. I have not tried the AJAX thing, but it looks promising. 

May 25, 2011 at 8:38 PM
Edited May 25, 2011 at 8:41 PM

Thanks for all your responses.

@sympmarc: I am not that good at development so I do not know how to make AJAX call to fetch the homepage of site B.

@spevilgenius: Your idea sounds good. As you said, its not the best but I guess it should make things work. So if possible, I would love to get a piece of the code that you have. Currently my function dies at: 

completefunc: function (xData, Status) { 
because the user I am querying does not return any result. And I dont know how to check whether there is no result from this function. I tried [if(xData != null] and also if (Status == 'success') but somehow it does not capture if there is no result from this operation.]
Quick question: So there is no such thing out there which we can use to add user to UIL ? (can't we use normal additem to do that?)
May 25, 2011 at 10:35 PM

Okay. To answer your last question first :-) Since your only option is client side code I will say no in that you could not do this without serious risk. I think that even if you could create a dummy group and then allow everyone to add users to the group I still doubt it would work or that you would get that far. When a user does the "trick" we are talking about, it is like they are visiting the site for the first time and this is what will add them to the UIL. Marc might know better on this part, but I thought they at least had to have some form of permission to the site or they would get "Access Denied". By giving "Authenticated Users" crud ability on a list, you create this effect as soon as you add an item via a webservice call. They have "touched" the site and are added. I will add some code later as it is buried in a virtual machine somewhere..

May 25, 2011 at 10:41 PM

Okay, Thanks a lot. much appreciated.

May 26, 2011 at 1:24 PM


An AJAX call to get the home page for Site B can be as simple as this:

   async: false,
   url: "http://domain/siteB/default.aspx"

I think that this all may be getting far more complicated than it needs to be.

Is the issue that you can't add a list item if the user isn't in the UIL for Site B (and you've proven this) or that you can't add the user to a Person or Group column in a list item in Site B until they are in the UIL?


May 26, 2011 at 4:09 PM

Yes, I think it is getting complicated as well. I like the AJAX call Marc, but trying this on a site where I am not in the UIL and "Authenticated Users" have not been given any access does not work. If I add "Authenticated Users" to the Visitor group and give that group at least read permission then it seems to work fine so far.

May 26, 2011 at 4:59 PM

Well, the user has to have some permissions on the destination site or else all of this is moot.

Does adding NT Authority\Authenticated users to the Visitors group do it?


May 26, 2011 at 5:03 PM

It works for me! I think this is the way to go.

May 26, 2011 at 6:37 PM
Edited May 26, 2011 at 6:40 PM


Say I am a userXYZ and I go to List A and start filling out New item form where there are 3 filed of 'Person or Group', I entered the Person1, Person2 and Person3 respectively.

Now, to add duplicate entry on List B on Site B - I need ID of the Person1,2&3 from Site B so that I can make it like 12;#Domain\UserName and then pass it in the webservice.

So problem is: Person2 never visited the site and so there is no ID for him so how should I call webservice with that format which is required inorder to populate the Person2 name at the destination field?


Also I believe - Even if I use ajax call to get homepage, it will add an entry for userXYZ and not Person2.

May 26, 2011 at 6:55 PM
Edited May 28, 2011 at 12:45 PM

OK, so this isn't about the *current* user being in the UIL on Site B, it's about the people selected in People Pickers. That's the more complex problem.

You can't impersonate another user in client-side script, so the AJAX fetch does you no good.

None of us has asked what version of SharePoint you are running. Is it 2007 or 2010? I'm guessing that you aren't running MOSS or 2010 Server with UPS, since then all users would already be replicating in from AD.

I will say once again that what you're doing is a kludge to get around an architecture which doesn't support it well.


May 28, 2011 at 5:36 AM


We are running MOSS 2007. And even if its kludge, its not like I have a choice.

May 28, 2011 at 10:24 AM

The only thing I know would work in this case is if you used text fields on list B for the users in lieu of a person field. I know that is not the most desirable, but it would work. You would store the name of the user from the first list as text in the second list. You could also do this as a link so it could look similar to a user field in list views. So have a link field that has a link like this:

<a href='http://speg1/tools/dart/_layouts/userdisp.aspx?ID=13'>Evil Genius</a>

So it is not exactly what you woul want but it would work. So you could check to see if the user is in your UIL for list b and if so create a link to that site's UIL and if not, you would make the link back to the other sites UIL

Does that make sense? Would that work for you?

May 28, 2011 at 12:52 PM

@PureLife My point is just that this is hard because it isn't the right way to solve the problem. I think something messy like what Dan is proposing may be where you end up. Sometimes taking the step back and rearchitecting to better meet the business requirement is the right answer. So aaying "Sure, you can have that, but here are the trade offs, and here are a few other options. Each one has its plusses and minuses."


May 28, 2011 at 6:04 PM
Edited May 28, 2011 at 6:05 PM


I thought the same thing, creating a text field on site B and then I can run a workflow which automatically converts the textfield to person field easily.

And yes, as "sympmarc" is saying its getting very hard everyday.  I didn't realize that it will be so hard to achieve. Once I started, all these problem starting to come up. Like for date field it should be in 2011-05-28 00:00:00 format and person should be in 12#;Name, Name.

But again, if you guys see any other way then please do let me know. I don't mind building the solution from scratch again but the problem is - both of them have their own list working fine and integrated into their own complex structure.

May 28, 2011 at 6:27 PM
Wacky idea: what about using a Page Viewer Web Part to just display the items in Site B?

May 28, 2011 at 7:26 PM

Thing is they use list B on site B in Excel to draw all chart and stuff... so that manager can see how many projects, its progress and how the resources are allocated.

And that's the reason why they need everything in a one list as a real entry. I even suggested them to display the list in bamboo roll-up kind of webpart so that all entries will be like a single list. 

But they are insisting for duplicate entry on the destination list.

May 31, 2011 at 3:32 AM

I think I'm running out of ideas. I also think that if you are going to duplicate the items *and* they are going to do charts and things from the data, you're going to have a synch issue. Maybe not, but I think you will. An ECM goal is to always store items and/or docs in one place and display them wherever they are needed.


May 31, 2011 at 10:01 AM

I have to agree with Marc here. I know that you already have the lists in place that do what you need separately on both sites, but this should be moved or repurposed to fit all the scenarios you are trying to cover. Either move both sites into the same site collection as sub sites (very big but you get the same UIL for both sites), or create one list in one location that will be displayed as needed and can be used in Charts/Graphs much more easily.

May 31, 2011 at 2:57 PM

PureLife, have you considered using a page view web part to just give them the illusion of the data in 2 places?

May 31, 2011 at 7:45 PM


Yes, I did consider it but It wont help as I need the item inside the list. So that they can do the operation on excel.


No, there is no sync issue as they are using Excel Macro to sync any changes made on the excel to sharepoint and other way around as well. I am no expert on Excel so can't comment much.

I guess now is the time to let them know that this is not possible and they have to give up on something... like use of page view webpart OR consider merging the list into one list and put the redirector on the older list.

May 31, 2011 at 7:54 PM

I think it's more "not advisable" than "not possible". With enough time and money, I'm sure there's a way to make it work, but it won't be pleasant.

Since you will be copying from Site A to Site B and then they may make changes via Excel in Site B, Site A could then not be in synch. That would be my concern.


May 31, 2011 at 8:10 PM

Yeap, thats true.

Anyways, Thanks all for your help. Much appreciated.