Using jQuery to return all members / users of a group #in #SP2010 #SharePoint
I’ve recently had cause to determine if a user is within a particular group in SharePoint and act upon the output.
Luckily the standard SharePoint web services allow to query for this information utilising the User Group service at location: http://<server>/_vti_bin/usergroup.asmx.
In particular the method GetUserCollectionFromGroup will provide the complete list including the Windows SAMAccountName (login name) as part of the return.
However, in this instance I was caught a little by a permissions problem. Although I could query the web service, it kept returning a status of “parsererror” and an output of “Access Denied”.
This was resolved by changing the group settings to allow “Everyone” to read the membership of the group.
Code Example
The following code utilises jQuery to access the web service:
Determining delegation mode and user via jQuery #in #ProjectServer #PS2010 #SP2010
In my current project I have recently had the requirement to determine whether Project Server 2010 was in delegation mode.
If the user was in delegation mode, we then passed the unique Display Name of the delegation user and passed it to a web service to return more data about the resource.
The information bar in PS2010 lets us know that we are in delegation mode and in jQuery we can interrogate this to get the information we need.
The following code uses jQuery to determine if we are in delegation mode and sets the Display Name and isDelegate variables accordingly:
Using jQuery to find the current logged in user #in #SP2010
Problem:
In MOSS 2007, we had methods to get the current logged in user by accessing some of the properties found in the Welcome Menu.
Although this is still the case in SharePoint Server 2010, there are some fundamental changes to the code and the way the Welcome Menu is rendered in SPS 2010 that means we have to do something slightly different to get the same result.
I have recently had a requirement to achieve this in my current project and thought I would share the basics with you.
Essentially we are still retrieving the information from an HTML element property in the Welcome Menu, but the menu itself is rendered in AJAX and therefore is not necessarily available as soon as the page is rendered and the DOM document ready state is set.
As a result of this, running JavaScript / jQuery on the page at either:
- $(document).ready
- _spBodyOnLoadFunctionNames
will not return the required result, since the menu elements we need to interrogate have not been rendered yet.
Solution:
- Set a timer to keep running a particular function to wait until the menu is rendered
- Stop the timer
- Interrogate the DOM as required using jQuery
Code Example:
Site Asset List View and jQuery issue and resolution #in
So recently I have been working on a project where we make use of the new Site Asset library capabilities in SharePoint 2010.
The Site Asset library comes with new functionality including pop-up previews of images and videos.
In particular, we are taking advantage of the fact that by uploading an image into the site library, 2 thumbnail versions are created for the list view preview and the pop-up preview.
This provides some good unique user experiences previously not seen in SharePoint out of the box before.
Anyway, to the jQuery issue:
It would appear that the Site Asset library (standard list view) uses the $ call for its JavaScript functions. This obviously conflicts with the standard way to call jQuery functionality:
This results in the error:
- Object doesn’t support this property or method
Resolution:
jQuery being implemented onto the master page doesn’t pose a problem since the SharePoint code is obviously called afterwards.
So by referencing jQuery in its longhand method:
you can use both the site asset functionality as well as any jQuery customisations that you may need to do.
Hopefully that helps out fellow SharePoint customisers out there.
#SP2010 Group List Items by External Data field–Field Display Missing #in
On an intranet I have been working on recently I came across a bug where the display of an External Data field in the 1st and 2nd level grouping is not shown when grouping by the BCS based item(s).
To provide a short term fix I created the following JavaScript to run on the page to solve the problem.
Essentially the values do exist in the DOM / HTML, but they are not displayed in the tags presented by the grouping.
NB: Please be aware that this solution relies upon JQuery.
Useful JavaScript Function: Hide Side Panel / Quick Launch – v4.master
On dashboard pages I often find I need more space. A quick way to do this is to place this into a Content Editor Web Part.
1 <script type='text/javascript'> 2 3 function v4MasterHideSidePanel() { 4 $('#s4-mainarea').children().eq(0).hide(); 5 $('#s4-mainarea').children().eq(1).css('margin-left', '0'); 6 } 7 8 $(document).ready(function(){ 9 v4MasterHideSidePanel(); 10 }); 11 12 </script>
This will hide the Side Panel / Quick Launch area on the v4.master – Master Page (Default Master Page for non-publishing sites)
NB: This method relies on JQuery