PART 1 : Working in MOSS using SPServices


After working in SharePoint 2010 and 2013 platform, it was bit difficult for us to work in SharePoint 2007.  SPServices came to our rescue. I have consolidated different scenarios we encountered and placed them in a single post below. So, it might help someone in the future.

Download the below files, save and provide a reference to these scripts before using the below script:

SPServices to populate people picker with logged-in username and to disable it in IE and Chrome:

<script type="text/javascript"> 
    var currentUserName ;   
    $(document).ready(function() {
    currentUserName = $().SPServices.SPGetCurrentUser({
    fieldName: "Title",
    debug: false
});
 alert(currentUserName);
 if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) //IF IE > 10
      {
          alert("Browser used for display is IE");          
      $("div[title='People Picker']").text(currentUserName);
      $("div[title='People Picker']").prop('disabled',true);
       $('img[title="Browse"]').css('display','none');
       $('img[title="Check Names"]').css('display','none');
        
      }     
      else if(navigator.userAgent.indexOf("Chrome") != -1 )
      {
          alert("Browser used for display is Chrome");  
   $("textarea[title='People Picker']").val(currentUserName);
      $("textarea[title='People Picker']").prop('disabled',true);
      $('img[title="Browse"]').css('display','none');
      $('img[title="Check Names"]').css('display','none');    
        
      }
 });
</script>

SPServices to check whether the user belongs to the specific SharePoint group(say, Admin):

<script language="javascript" type="text/javascript">
$(document).ready(function() 
{
    $().SPServices({
      operation: "GetGroupCollectionFromUser",
      userLoginName: $().SPServices.SPGetCurrentUser(),
      async: false,
      completefunc: function(xData, Status) {
        if($(xData.responseXML).find("Group[Name='Admin']").length == 1)
        {
      alert("You belong to admin group");
  //your code for admin users
    }
        else
        {
          alert("You do not belong to admin group");
  //your code for non-admin users
        }
      }
   }); 
}); 
</script>

SPServices to perform read operation:

<script>
$(function(){
getListItems();
});
function getListItems(){
var method = "GetListItems";
var list = "Demo";
var fieldsToRead =  '<ViewFields></ViewFields>';
var query = "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>"+ID+"</Value></Eq></Where></Query>";            $().SPServices({
operation: method,
async: false,
listName: list,
CAMLViewFields: fieldsToRead,
CAMLQuery: query,
completefunc: function (xData, status) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
var eTitle = ($(this).attr("ows_Title"));
alert(eTitle);
});
}
});
}
</script>

To get the latest version of SPServices and to know more about it, visit this link

Advertisements

Hiding quick launch in MOSS


In this article, let us see how to hide quick launch and blank area in list forms in MOSS site.

To hide quick launch in home page, you can use the below css:

.ms-quicklaunch
{
display:none;
}
.ms-navframe
{
display:none;
}
Before applying css
home-with-quick-launch
After applying css
home-without-quicklaunch

If you open list forms, you can see the blank space inspite of quick launch. Inorder to hide it, go with the below css:

.ms-navframe
{
display:none;
}
Before applying css:
form-with-blank-space
After applying css:
form-without-blank-space

Query Strings in SharePoint


Let us see some of the query strings used in SharePoint:

  • contents=1 ->used to troubleshoot the sharepoint page.When it is appended at the end of the url as:

https://…/sitepages/Home.aspx?contents=1

it takes us to webpart maintenance page where we can find the webpart causing the error by trying to close each one and deleting the problematic webpart

  • IsDlg=1->used to hide the header and quick launch(i.e. chrome).Generally used in SharePoint forms.
  • FilterField1=Gender&FilterValue1=Male(FilterField1=columnname&FilterValue1=columnvalue)->used to filter sharepoint list webpart with the condition, Gender=”Male”
  • FilterName=Hobbies&FilterMultiValue=Painting;Reading(FilterName=columnname&FilterMultiValue=columnvalue1; columnvalue2)->used to filter sharepoint list with multiplevalues in singlecolumn
  • PageView=Shared&ToolPaneView=2->used to show the edit mode of the page, browse and add the webpart
  • PageView=Shared&ToolPaneView=3->used to show the edit mode of the page, search and add the webpart
  • SortField=Hobbies&SortDir=Desc(SortField=ColumnName&SortDir=Desc/Asc) ->used to sort the sharepoint list by Hobbies in Descending order
  • _layouts/viewlsts.aspx -> To go to “All Site Content” Page