SharePoint 2010/2007: Setting value of "Person or Group" Column Using SPService

Context:
Well I had a list called employees comprising of  two columns: i.e. Title (Single line of text) and  a Person or Group type column that is to be filled with the user. I was trying to fill this column with the current user.

Solution 
So here is the code that will aid in achieving just that.









There are number of aspect in this code that need to be addressed. First this is the format of the string that fill s the person or group type column. In normal cases, the item in Person or Group type column shows up in the following format:
ID;#Domain\UserName.

Here what I used:
"-1;#"+loggedinUser

So it means you don't need to find ID to form the aforementioned string, rather direct concatinating -1 to the username can do the magic. If somebody is totally unaware about how to use this code, I used content query webpart (out of the box webpart) to write this code.

Update:
well later I tried to make use of the same technique in the server side code and this turn out to be valid for backend as well.

Reference:
http://spservices.codeplex.com/discussions/277482


Vaqar Hyder

E: vaqar.hyder3567@gmail.com

A:

Siebenbürgen Straße 2/1, Korntal-Münchingen, 70825, PK

Hire me on Freelancer.com

Comments

  1. Thank you Vaqar. Worked for me.Good Tip.

    ReplyDelete
  2. Thank you. It is important to know that you can use "-1" as the ID. The IDs of users are different depending on what site collection they are on. John Doe might be #100 on SC-1 and #5555 on SC-2. So if you're pulling a user from SC-1 to save data about him in a list on SC-2, storing him as #100 would save the wrong user! MSFT needs to document stuff like this better, it's almost impossible to find anything online about it.

    ReplyDelete

Post a Comment

Popular posts from this blog

SPFx: Develop using SharePoint Framework without Installing all the dependecies.

SharePoint Online: Elevated Permissions....with love

Powershell: Filling up an Existing Excel Sheet with data from SQL Server