Posts

Showing posts from 2015

Add fields to a list in SharePoint 2010 with JQuery and CAML Query

The jquery javascript code below will add a field, named "Page" to the list in the variable myList. I use CAML Query to create the field. Note: the code snip is missing the function call. <p id="hits"></p> <script type="text/javascript" src="/Style Library/js/jquery-1.11.3.min.js"></script> <script type="text/javascript" src="/Style Library/js/jquery.SPServices.min.js"></script> <script type="text/javascript"> webURL = window.location.protocol + '//' + window.location.host + _spPageContextInfo.siteServerRelativeUrl; var myList="MarksHitCounter"; // the name of your list function addFields()  {   var nfields = " \   <Fields> \    <Method ID='1'> \     <Field Type='Text' DisplayName='Page' ResultType='Text'></Field> \    </Method> \    </Fields>";   $().SPServices...

Determining if a SharePoint 2010 list exists through jquery

Below is a javascript jquery function to determine if a specific list exists within the current site. This was the first step in the overall project, but this is useful on its own.  The addFields() function will be described later.  The variable webURL is valuable because it constructs the site URL regardless of the page URL. <p id="hits"></p> <script type="text/javascript" src="/Style Library/js/jquery-1.11.3.min.js"></script> <script type="text/javascript" src="/Style Library/js/jquery.SPServices.min.js"></script> <script type="text/javascript"> webURL = window.location.protocol + '//' + window.location.host + _spPageContextInfo.siteServerRelativeUrl; var myList="MarksHitCounter"; // the name of your list function addListIfItDoesntExist() {  var listExists=false;  $().SPServices  ({   operation: "GetListCollection",     async: false, ...

SharePoint 2010 List Template IDs

Handy little reference. 100   Generic list 101   Document library 102   Survey 103   Links list 104   Announcements list 105   Contacts list 106   Events list 107   Tasks list 108   Discussion board 109   Picture library 110   Data sources 111   Site template gallery 112   User Information list 113   Web Part gallery 114   List template gallery 115   XML Form library 116   Master pages gallery 117   No-Code Workflows 118   Custom Workflow Process 119   Wiki Page library 120   Custom grid for a list 130   Data Connection library 140   Workflow History 150   Gantt Tasks list 200   Meeting Serie...

Filling a drop down with distinct values from a SharePoint 2010 list

In the code below, I'm first filling the select box with distinct items (Contract Numbers) from the title field. Once one is selected, I use that field to query and display data. First, I call the function  getContracts();  which executes this CAMLQuery <Query> \ <OrderBy> \ <FieldRef Name=\'ContractNum\'/> \ </OrderBy> \ </Query>'; This selects everything with an order by which puts lists all the duplicates sequentially. Then as you loop through each item if it doesn't match the previous one contractnum = $(this).attr("ows_Title"); if(contractnum != prevcontract) { $("#outputdrop").append("<option value='" + contractnum + "'>" + contractnum + "</option>"); prevcontract = contractnum; } you add it to the drop down and set the value of the prevcontract equal to the current one so that the IF condition will fail if the next one matches...

Querying a SharePoint list with a date via CAML Query

I have this SharePoint list with some data in it.  There's a start date, and an end date among other fields.  The user wanted to be able to enter a specific date and then find out all the contracts that were active on that date.  I could build a view to show that data, but they'd need to provide the date and create a view which is not really what they wanted. All they wanted was output on the screen. So... I built this .js file with a CAML Query to grab the right data. The same company could have multiple contracts an should only be counted once, so that's why you see  if(contract != prevcontract)  below. <h3><p id="outputreport" >Number of Prime Companies with Afghanistan Deployments.  Enter a date:</p></h3> <input id="inputdate" type="text" name="start" > <input type="button" value="Submit" onclick="getPrime(document.getElementById('inputdate').value);"...

Creating a "Google Style" filter of a SharePoint List

Here is a simple jquery search which automatically filters whatever content is on the page as you type. You might need to create a view which shows all items since it can't search page 2 or anything grouped and collapsed. You'll need the jquery .js file, but that's it.  This is a very powerful script which I put in a content editor web part, exported the webpart .dwp file, then imported it into each site collection(s) making it available to all sites. <script type="text/javascript" src="/Style Library/js/jquery-1.11.3.min.js"></script> <input type="text" id="filter" onkeyup="keyupfunc(document.getElementById('filter').value);"></input> Search Contacts <script type="text/javascript"> function keyupfunc() { var list = $("table.ms-listviewtable"); var listItems = $("table.ms-listviewtable tr:not(.ms-viewheadertr)"); var input = $("input#filt...

Fixing: Screen Flicker bug in IE by disabling the Modal Dialog Box in SharePoint 2010

There's a bug in the latest version of IE that causes a flicker in the greyed out section.  This can be very distracting and has caused complaints and seizures.  Okay, maybe not seizures, but it could happen. To rectify this, as we have no control over the browser or patching, we decided to set every list to open in the form view, not the modal dialog view. So, we needed a PowerShell script to accomplish this since we have hundreds of sites and thousands of lists. The PowerShell command to set this is:       $list.NavigateForFormsPages = $true       $list.update() Note that the setting NavigateForFormsPages should be set to true for Form or False for modal dialog. Now we need to loop through each site and hit each list.  Here's the code I came up with: ############################################################################# $webcount = 0 $listcount = 0 $webs = (Get-SPSite -limit all | Get-SPWeb -Li...

Using an external file in a master page

In our setup, there are frequent changes that get requested that should apply to all sites. As these sites cross site collections, each one has a custom master page although it's the same master page for all sites. In order to make these changes easier, I created a .js file containing document.writes to display my HTML code: document.write('<div class="SiteTitle"><a href="/">(Acronym for title which will change next week)</a></div>'); Any HTML code can go in there, but SharePoint code like this cannot: <SharePoint:SPLinkButton runat="server" NavigateUrl="~sitecollection/"> <SharePoint:SiteLogoImage  LogoImageUrl=" http://sharepoint.name/SiteAssets/MasterPage%20Assets/sitelogoimage.png " runat="server"/>  </SharePoint:SPLinkButton> The SharePoint tags are executed server side while the js is client side code. However, in the example above, changine the image ...

SharePoint 2010 Hide Quick Launch

Handy Javascript code to hide the quick launch (left nav) bar.  just add it to the html on the page or a content editor web part. <style type="text/css"> /*--Hide Quick Launch--*/ #s4-leftpanel{ display:none } .s4-ca{ margin-left:0px } </style>

SharePoint 2010 Powershell script displays all the Site Collection Administrators for a given web application.

Here's a useful powershell script that I'm blatantly stealing borrowing from here .  This script displays all the Site Collection Administrators for a given web application. $siteUrl = Read-Host "Enter Site URL" $rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl) $spWebApp = $rootSite.WebApplication foreach ($site in $ spWebApp.Sites ) { foreach ($siteAdmin in $site.RootWeb.SiteAdministrators) { Write-Host "$($ siteAdmin.ParentWeb.Url ) - $($siteAdmin.DisplayName)" } $site.Dispose() } $rootSite.Dispose()

SharePoint 2010 Developer Dashboard

Image
The Developer Dashboard can be a handy little debugging tool that will give you all sorts of info. To turn it on, use the STSADM command: stsadm -o setproperty -pn developer-dashboard -pv on or to not screw up your page, try setting it to on demand: stsadm -o setproperty -pn developer-dashboard -pv ondemand When it is on demand, click the icon (circled): to see something like this on the bottom of the page: Developer Dashboard •Request (GET:http://xxxxxxxxxxxx:80/xxxxxxxxx/default.aspx) (493.96 ms) BeginRequestHandler (0.11 ms) PostAuthenticateRequestHandler (0.12 ms) PostResolveRequestCacheHandler (50.32 ms) GetWebPartPageContent (33.00 ms) GetFileAndMetaInfo (32.56 ms) GetWebPartPageContent (127.62 ms) GetFileAndMetaInfo (127.28 ms) PortalSiteMapDataSource: Determining Starting Node (0.01 ms) PortalSiteMapDataSource: Determining Starting Node#1 (0.01 ms) Add WebParts (6.17 ms) xxxxx Shared Calendar (0.64 ms) xx Logo (0.15 ms) Site Image (0.12 ms) xxxx Org Char...