Displaying other people picker column properties on a view using spquery.js and spservices.js in MOSS 2007

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/22735

Question

We have a custom list with a person column. Want to display that persons Department on the list view. Possible with jquery/spservices?

I have a jquery script that returns the currently logged in users Department. Just need that code for every row, by the person column.

I have some jquery and spservices code that returns the Department of the currently logged on user. What I need is Jquery code that creates a new column in a list view and plugs in the department for a specific person column in that row. Anybody know where I might find such a jquery example.

<script src="http://xxxxx/jquery/jquery.js" type="text/javascript"></script> 
<script src="http://xxxxxxxxxxx/jquery/SPServices.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 
    var Dept = $().SPServices.SPGetCurrentUser({ 
        fieldName: "Department", 
        debug: false 
    }); 
    alert(Dept);
}); 
</script> 
Was it helpful?

Solution

SPGetCurrentUser isn't what you want, as it will only return the values for the current user. It sounds like what you want is the Department for whichever user shows up in each item in a list view (LVWP).

Since you are using MOSS, you could take a look at the UserProfileService. This would allow you to get the user profile for any user and from it obtain the user's Department.

Another thing to consider is usdng a Data View Web Part (DVWP) rather than a LVWP so that you can user the User Information List (UIL) in an AggregateDataSource and grab the user's Department from the UIL. However, that will only work if your UIL consistently has the Department populated. Generally the uer profile is more reliable.

However you get the value, you'll then want to add a column to each item in the LVWP and populate it with the Department value. There are lots of example for how to insert elements in the DOM with script, but I'd start with the jQuery documentation and go from there.

OTHER TIPS

For this I create a new person group column set to disply the Department field. Then using SPServices, return the account property and update my department field fwith the users account which in turn displays the department. This is code I'm using on a form to add phone, email, and department to people picker fields specified to return those values.

$(document).ready(function() {   
    var User = $().SPServices.SPGetCurrentUser({   
        fieldName: "Name",   
        debug: false   
    }); 
    $("textarea[title='People Picker']").val(User);
    $("div[title='People Picker']").text(User); 

The other method would be to create a single line of text column then update that column with the return from the spservice call. Something like, assuming your column has a display name of User Department,

$("input[title='User Department']").val(Dept);
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top