Posts

Showing posts from September, 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...