Skip to content

Instantly share code, notes, and snippets.

@rmilton
rmilton / ParseSharePointSearchResults.js
Created July 28, 2015 18:22
Parses the complex object returned from the SharePoint 2013 Search REST API into a simple object with an array for each row. For example, transforms data.d.postquery.PrimaryQueryResult.RelevantResults.Table.Rows.results[1].Cells.results[3].Value into data[1].FirstName
function ParsePostQueryData(_data) {
var data = JSON.parse(_data.body);
var results = data.d.postquery.PrimaryQueryResult.RelevantResults.Table.Rows.results;
var obj = [];
$.each(results, function(index, value) {
var cells = results[index].Cells.results;
var cell = {};
$.each(cells, function(i,v) {
cell[cells[i].Key] = cells[i].Value;
@rmilton
rmilton / StatsDoughnut.htm
Last active August 29, 2015 14:17
ChartJS doughnut graph with animations
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="http://www.chartjs.org/assets/Chart.js"></script>
<style>
div.number {
position:absolute;
background-color: #F7464A;
top: 15px;
left:37px;
@rmilton
rmilton / LinksBoxYellow.js
Created March 2, 2015 22:11
JSLink to display a links list in a scrollable, colored box
(function () {
var overrideCtx = {};
overrideCtx.Templates = {};
//Tempate overrides
overrideCtx.Templates.Header = function (ctx) {
var html = '<div class="linksBox-wrapper">';
html += '<div class="linksBox-header linksBox-yellow">';
html += ctx.ListTitle;
@rmilton
rmilton / StartWorkflowCSOM.cs
Last active August 29, 2015 14:16
Start a SharePoint 2013 List Workflow with CSOM
// credit: http://www.vrdmn.com/2014/05/managing-sharepoint-2013-workflows-with.html
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.WorkflowServices;
using System.Collections.Generic;
using System.Linq;
using System.Security;
namespace CSOMWorkflow
{
class Program
@rmilton
rmilton / Managed Service Account Password Retrieval
Created April 27, 2014 14:35
Retrieve the password in an unsecured string of an account registered as a Managed Service Account in SharePoint. Tested on SP2013 but should also work on SP2010.
using System.Runtime.InteropServices;
using Microsoft.SharePoint.Administration;
var managedAccounts = new SPFarmManagedAccountCollection(SPFarm.Local);
foreach (SPManagedAccount managedAccount in managedAccounts)
{
var securePassword = (SPEncryptedString)managedAccount
.GetType()
$(document).ready(function () {
var reportViewerId = $('div[id$=_ReportViewer]').attr('id');
Sys.Application.add_load(function () {
$find($('div[id$=_ReportViewer]').attr('id')).add_propertyChanged(viewerPropertyChanged);
});
})
function viewerPropertyChanged(sender, e) {
@rmilton
rmilton / Capture Cell Changed in Excel Web Access webpart
Created April 15, 2014 12:17
This snippet shows how to trigger on a cell changed event when an Excel workbook is embedded in a SharePoint WebPart page with the Excel Services Web Access WebPart. The code uses the EWA JavaScript API.
// get reference to the (first) Excel Web Access webpart on the page
var ewa = Ewa.EwaControl.getInstances().getItem(0);
// add an event receiver for capturing a selection change
ewa.add_activeCellChanged(cellChangedHandler);
function cellChangedHandler(args) {
args.getWorkbook().getActiveSelection().getValuesAsync(0,getRangeValues,null);
}