Category Archives: Utilities

SPJS-Utility updated with support for querying large lists

By request I have added support for querying large lists (over 5000 items) using “spjs_QueryItems” or “spjs.utility.queryItems” in SPJS-Utility.js

If you use this for example with the DFFS Plugin “Autocomplete”, and have hit this error:

The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator

You can now update SPJS-Utility.js to fix this problem.

Please note that these functions are undocumented and mostly used internally from the different SPJS functions and solutions. If you are interested in using these functions in your own code, dig into the code to discover how it works, or ask a question in the forum.


You find SPJS-utility.js here.


Approve or reject list items

I have previously posted a JavaScript solution for approving multiple documents or list items. This is an updated version that adds two buttons in the ribbon: one for “Approve” and one for “Reject”. Refer the original solution for details, but please note that the variables for controlling the text values have changed.

Use this code to load the solution in a list view
<script type="text/javascript" src=""></script>
<script type="text/javascript" src="/Scripts/ApproveOrRejectSelected.js"></script>
Change the default text values

If you are happy with the default, English text, you can skip this next step.

To override the default text, add this to the CEWP below the script reference to “ApproveOrRejectSelected.js”,and change the text as you like:

<script type="text/javascript">
spjs.contentApproval.text = {
	"approveBtn":"Approve selected",
	"rejectBtn":"Reject selected",
	"groupLabel":"Approve or Reject",
	"working":"Processing items...",
	"done":"{0} items processed"

You can wrap it like this to switch based on the logged in users language (in MUI environments):

	case 1044:
		// Add Norwegian values
		spjs.contentApproval.text = {
			"approveBtn":"Approve selected",
			"rejectBtn":"Reject selected",
			"groupLabel":"Approve or Reject",
			"working":"Processing items...",
			"done":"{0} items processed"
	case 1031:
		// Add German values
		spjs.contentApproval.text = {
			"approveBtn":"Approve selected",
			"rejectBtn":"Reject selected",
			"groupLabel":"Approve or Reject",
			"working":"Processing items...",
			"done":"{0} items processed"
Download ApproveOrRejectSelected.js

Get the file here.


SPJS Simple tooltip

By request I have “ripped” the DFFS tooltip from DFFS. This code can use to create a custom tooltip with the same style and function as in DFFS. This means that you can have a hover-over tooltip that sticks if you click the hover-image.

Take a look at it, and familiarize with the code before asking questions.

The tooltip text or HTML is added to the variable “SPJS_SimpleTooltipContents”, and the “key” is used in the image “onmouseover” to pull in the correct tooltip.

The code
<style type="text/css">
div.SPJS_SimpleTooltipPlaceholder img{
	border:1px #9F9E9C solid;
	height: 16px;
	border-bottom:1px silver solid;
	width: 16px;
	height: 16px;
	background-repeat: no-repeat;
	background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuM4zml1AAAAB5SURBVDhPzZJBDoAgEAN5CG/jF74fGewigSUcOOgkTaTtrhoN/yHnHIuSFGU3djkFAuMqaiWu5RlJ0QvmkzXqEqkfBneBV+TsefMrAIEKK9bDBgUVR/bDQEnlkaO7G+slBCr0cPa8eUkxjz/j8Y9EiSVoesRd/hUh3IlkrlzxjRMpAAAAAElFTkSuQmCC);

<script type="text/javascript">
var SPJS_SimpleTooltipContents = {
	"helpText1":"<div style='width:200px;'>This is a custom tooltip for field 1<div style='color:red'>You can use HTML</div></div>",
	"helpText2":"<div style='width:200px;'>This is a custom tooltip for field 2<div style='color:red'>You can use HTML</div></div>"

var SPJS_SimpleTooltip = {
		"isSP13":typeof _spPageContextInfo !== "undefined" && _spPageContextInfo.webUIVersion === 15 ? true : false
		var p = $(elm).position(), l = {};
		if($("#SPJS_SimpleTooltipPlaceholder").length === 0){
			$("body").append("<div id='SPJS_SimpleTooltipPlaceholder'></div>");
		$("#SPJS_SimpleTooltipPlaceholder").html("<div style='padding:3px;'>"+(SPJS_SimpleTooltipContents[key] !== undefined ? SPJS_SimpleTooltipContents[key] : "The tooltip for key \""+key+"\" was not found.")+"</div>").attr("pin","0").css({"position":"absolute","left":p.left+15});
		// Check left pos
		l.l = p.left+30; = $("#SPJS_SimpleTooltipPlaceholder").width();
		l.ww = $(window).width();
		if(l.l + > l.ww){
			$("#SPJS_SimpleTooltipPlaceholder").css("left",(p.left - (l.l + - l.ww)));
		if($("#SPJS_SimpleTooltipPlaceholder").find("div.SPJS_SimpleTooltipHolderClose").length === 0){
			$("#SPJS_SimpleTooltipPlaceholder").attr("pin","1").prepend("<div class='SPJS_SimpleTooltipHolderHead'><div class='SPJS_SimpleTooltipHolderClose' onclick='SPJS_SimpleTooltip.hide(true);'></div></div>");
		if($("#SPJS_SimpleTooltipPlaceholder").attr("pin") !== "1" || c){

This HTML code shows you how to use the tooltip
<!-- Example HTML -->
<table cellpadding="0" cellspacing="0">
		<td valign="top">Field 1: </td>
		<td valign="top"><input style="width:300px;" type="text">
			<img onmouseover=",'helpText1')" onmouseout="SPJS_SimpleTooltip.hide()" onclick="" src="/_layouts/images/hhelp.gif" border="0">
		<td valign="top">Field 2: </td>
		<td valign="top"><input style="width:300px;" type="text">
			<img onmouseover=",'helpText2')" onmouseout="SPJS_SimpleTooltip.hide()" onclick="" src="/_layouts/images/hhelp.gif" border="0">
<!-- Example HTML -->

PS: It’s the <img> tags that calls the tooltip, the other HTML is for demonstration only.

I hope you can make use of this code.


SPJS Poll for SharePoint v2.0

I have brushed up the 5 year old solution Poll for SharePoint, to change the deprecated “Google Image Charts to use Google Charts (AKA Google Visualization). The Image Charts are officially deprecated, but will probably continue working for some time, but to ensure you have a working solution, you should upgrade to this new version.

Please note that there are some changes to the Content Editor Web Part code, so existing users must not only update the script file, but also look over the CEWP code and make some small changes.

This code lets you generate polls without the need for server side installed WebParts.
Change log
March 15, 2015
v2.0 released. This one has no new functionality, but the code has been brushed up, and now the charts are generated using “Google Charts” rather than “Image Charts”.


Result with column chart


How to set it up
Create a custom list with the following fields
  • Answer: Single line of text
  • Question: Single line of text

Name it anything you like, but keep the display name fairly simple (no special characters) as you will use the display name in the CEWP code.

CEWP code

The CEWP code below refers jQuery from Google. If you have a local copy of jQuery you can change the script src. You find the code for the file “SPJS-Poll.js” at the bottom of the page.

NOTE: You must change the script src for the file “SPJS-Poll.js” and “spjs-utility.js” to point your instance of the files – the CEWP code will not work unless you do this.
Place this code where you want the poll to appear:
<div id="SPJS_Poll"></div>
<link type="text/css" href="/Scripts/Poll/spjs_poll.css" rel="stylesheet">
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src="/Scripts/spjs-utility/spjs-utility.js"></script>
<script type="text/javascript" src="/Scripts/Poll/SPJS-Poll.js"></script>
<script type="text/javascript">

// Preload the chart solution
google.load("visualization", "1", {"packages":["corechart","table"]});

// If you want to override these texts, uncomment the object and localize as you like.
	spjs.poll.text = {
		"showResultBtnText":"Show result",
		"pollNotActiveText":"The poll is not active prior to {0}",
		"pollEndedText":"The poll ended on {0}",
		"alreadyRespondedText":"You answered: ",
		"totalResponsesLabel":"Total responses: ",


				id:"Poll_3", // Allowed characters id a-z, 0-9 - and _
				start:"01/02/2015", // format: mm/dd/yyyy
				end:"03/15/2015", // format: mm/dd/yyyy
				q:"What is your favorite junk food?",
				a:["Pizza","Hot dog","Hamburger","Neither of them"], // Leave empty for free input				
				forceLowerCaseAnswer:false, // Group result by lowercase				
				chart:"col", // table, bar, col or pie


Object attributes explained

  • pollAnswerListName: DisplayName or GUID of the list that stores the answers
  • listBaseUrl: The baseUrl of the site. This is like “/sites/hr” when the list is located in the site “hr” under “/sites”. Use L_Menu_BaseUrl (or omit the property) for current site.
  • id: The unique id of the poll. All poll answers are stored in a list and this id is used to separate each poll
  • start: Start date in the format mm/dd/yyyy
  • end: End date in the format mm/dd/yyyy
  • singleResponse: true for one reply per user, false for unlimited number of replies
  • q: Poll question. To have a linefeed in the question, use <br>
  • qStyle: CSS syntax style
  • aStyle: CSS syntax style
  • a: Answers in an array format. To use free input and not predefined answers, leave the array empty.
  • color: Colors for the chart in an array format. This must have the same length as the previous parameter – one color for each answer
  • forceLowerCaseAnswer: Primarily for use with free input to avoid getting two “series” when the only difference are uppercase characters.
  • chart: “bar” for bar chart, “col” for column chart, “pie” for pie chart or “table” for a plain table.
  • height: Height in pixels
  • width: Width in pixels
Regarding free input

If you leave the attribute “a” as an empty array, the user can supply free text as “answer”. When using free input, the result are automatically presented as a table.

Download code

The code for the file SPJS-Poll.js. You find spjs-utility.js here.

Questions or feedback

Post any questions in the forum


DFFS v4.250 released

This release has multiple changes and additions from the previous production release (v4.200). You find the complete changelog her:

I will show you one enhancement in particular – the new options for side-by-side headings and labels:

This layout is achieved with this configuration
In the “Tabs” tab I have added this configuration:

Please note how the headers are moved to the side-by-side column using the “Header ID”.

In the Side-by-side tab I have added these labels:


In the Custom CSS section in the Misc tab I have added this code:
transform: rotate(-90deg);
td.sbs_tdIndex_1, td.sbs_tdIndex_2, td.sbs_tdIndex_3, td.sbs_tdIndex_4{
	width:350px !important;
td.sbs_Field, td.sbs_Field div.sp-peoplepicker-topLevel{
	width:250px !important;
Comments and feedback

Please add any comments, questions or feedback in the forum:


SPJS-Lookup: Convert a single line textfield to a dropdown select based on a query

Change log

You find the latest change log here:

v1.11 (August 17, 2015):
Fixed an error resulting in existing values not validating when loadign an item in EditForm.

v1.10 (February 28, 2015):
If you want to have the same list of choices in multiple fields, you can now populate an unlimited number of fields from one single query. All you have to do is to use an array of fields in the parameter “fieldToConvertToDropdown”. See code example below for details.

v1.05 (February 12, 2015):
Added option to specify a folder in the query. The custom CAML or query will search only in the specified folder. Please note that you must update spjs-utility.js to v1.205 or later.

Removed a border around an image that occurred in SP 2010.

Fix for “addToExternalList” when using the solution for multiple fields in a form, and more than one targetted the same lookup list. The callback would refresh the bottom SPJS-Lookup field as the “argument object” was not uniquely identified.

January 21, 2015
Fixed a bug where I had mistakenly used the display name and not the FieldInternalName as identifier for the fields.

This is a remake of a solution I posted in 2009. It does mostly the same as the old one, but the code is overhauled, and it is now compatible with DFFS.

What does it do?

This solution is used to convert a single line of text field into a dropdown select. The options for this select is the result of a query you build in the function call. You can use it to query any list within the same site collection. You have an option to add new values to the “lookup list” on the fly, or to enter a value free hand.

This solution is compatible with SP2007, SP 2010 and SP2013.

DFFS plugin

This is compatible with DFFS, but you will not find a dedicated “tab” in DFFS to set it up. You must therefore use the same code for both DFFS and standalone use. With DFFS you have the option to put the function call in the Custom JS section in the Misc tab.

The code

If you use it as a standalone solution, you must refer jQuery and SPJS-utility.js in addition to SPJS-lookup.js.

In a standalone setup it will look something like this
<script type="text/javascript" src="/code/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/code/spjs-utility.js"></script>
<script type="text/javascript" src="/code/spjs-lookup.js"></script>
<script type="text/javascript">
// Put the contents from the code block below here.

If you use it with DFFS, the only extra script you need is this (in the DFFS_frontend CEWP) – put it below the reference to spjs-utility.js:

<script type="text/javascript" src="/code/spjs-lookup.js"></script>
The function call
		"folder":"", // Leave empty to search in all folders
		"CAML":null, // If used, the rest of the filterObj settings are disregarded
		"linkText":"Write your own value"
		"customFunction":null, // Function name as a string. If a function name is supplied, this will be used in stead of the default function. The function will be passed the argument object as a parameter.
		"linkText":"Add new item",
		"saveNewItemText":"Save new item"
Parameter details
  • fieldToConvertToDropdown: This is an array or FieldInternalNames of the fields in the current list that you want to convert to a dropdown. Specify multiple fields like this: [“FirstField”,”SecondField”] to have all server the same options based on one single query.
  • listName: This is the display name or the list GUID of the list you read the options from.
  • listBaseUrl: This is the base URL of the list you read the options from. If the list is on the root site of your domain, the value will be an empty string like this “”. If it is on a managed path, it will be something like this: “/Sites/MySite”
  • optTextFieldInternalName: This is the FieldInternalName of the field that represents the options you want to show in the dropdown select.
  • sortFieldName: This is the FieldInternalName of the field you want to sort the options by. Most likely the same as “optTextFieldInternalName”.
  • filterObj
    • on: true or false to tell if the options should be filtered. If false, all options will be shown.
    • folder: Here you can provide a relative URL to a folder like this: /Sites/MySite/Lists/MyList/MyFolder/MySubFolder
    • CAML: Here you can provide the full CAML query to filter by. If this is left as null, the other options below will take effect.
    • fin: The FieldInternal name you want to filter on.
    • isLookup: true or false. If you filter by a text value, use false. If you filter by an ID in a lookup field, set it as true.
    • operator: Use anu valid CAML operator like “Eq”, “Neq”, “BeginsWith” or “Contains”.
    • filterVal: This is the value you want to filter by.
  • dropDownDefaultvalue: This is the default value in the dropdown when it has not been selected.
  • addYouOwnValue
    • on: true or false. This controls whether or not to show a link to “kill” the dropdown and show the underlaying text field.
    • linkText: This is text on the link.
  • addToExternalList
    • on: true or false. This controls whether or not to show a link to add an item to the list you are pulling the options from.
    • customFunction: If you want to override the built “addToExternalList” function, add your custom function name here like this: “myAddListItemFunc”. The function itself must be present in the page, and it will get the full “argObj” passed to it as a parameter.
    • linkText: The link text that initiates the “addToExternalList” function.
    • saveNewItemText: The text on the “save” link.
  • debug: true or false. If true, the underlaying text field will not be hidden, and you will see a yellow information panel in the top of the page.
Setting a value in a field with this solution activated

To set the value of a field when using this solution, use code like this:

spjs.lookup.setValue("FieldInternalName_of_your_field","The value you want to set");

This will also work with DFFS and will trigger any rule currently configured for the underlaying text field (by triggering the blur-event).

Questions or feedback

Please use the forum for all questions related to this solution.


DFFS v4.210 BETA

BETA 2 of DFFS frontend released January 19, 2015
Please note that this version is BETA and is NOT intended for a production environment.

I have released a new BETA version (v4.210 BETA) of DFFS, but I need help testing it as I have made some fundamental changes to how “initial values” are retrieved, and to how read only fields are “styled” to maintain the correct width of the field. There are also a quite a few bugfixes and other changes that I would like your feedback on.

The full change log is as follows
Changes and new features
  • Changed how read only fields are “styled” when using side-by-side to try to maintain the width of the field. This change needs testing – let me know how it works in your setup.
  • Changed how initial value is retrieved when the form loads. Previously DFFS read the values from the fields using the function “getFieldValue”, but now it uses a web service call to get the current item metadata from the DB. This is done to try to overcome the problems some have been experiencing with people pickers not being ready when set to readonly when the form loads. This change needs testing – let me know how it works in your setup.
  • Changed how you reorder fields in tabs in the backend.
  • Boolean values will be displayed as checkboxes in DispForm.
  • New: Changed tab color on hover to a slightly lighter color (update CSS file for the frontend).
  • Added class “dffs-accordion-activePanel” to active accordion panel. You can use this class for your “custom code”.
  • New: Added support for comparing dates with hours and minutes. Please note that you cannot use hour and minute when comparing dates in DispForm.
  • New: Added “between” operator.
  • New: You can now add a new field to the list from the Misc tab (SP 2010 and 2013 only).
  • When no configuration has been created for a form, the overlay would time out with “This took forever”.
  • When using side-by-side and hidden label you could got a linefeed after the star that indicates that the field is required.
  • Selected tab index trigger: added “change event” as this trigger only fired on load and not on change of tab.
  • Only the first rule using the trigger “Selected tab index” could be used in “and these rules are true”.
  • The rule debug output was missing “run these functions”.
  • Date pickers: In some cases, errors would appear in the developer console in SP2013 when operating date pickers.
  • Date pickers: The “blur” event was not triggered on the “master” datepicker when using “linked” datepickers and modifying the “slave”.
  • When a field was configured in DFFS, but it was not in the current content type, you could in some cases get an error like “unable to get the property “hidden” of undefined or null reference” in the developer console.
  • The Attachement field will no longer trigger the “orphans” tab.
  • In the frontend I have changed from referring jQuery as $ to use spjs.$ due to an error in SharePoint when using rich text fields and “Insert > Link > From SharePoint” as the file “assetpicker.js” will “kill” jQuery by overriding the global $ variable. This would result in a complete halt in all the functionality in DFFS (and other plugins using jQuery). Please note that other plugins must also be updated. Look at the change log for each one to see which one have been updated.
  • Scroll to first input will no longer make the form scroll down. If the first input is off the visisble sceen, it will not get focus.
  • BETA 2: Fixed bug occurring when you for some reason had duplicates of the configuration in the configuration list. Now only the first “match” will be used, and you will no longer see duplication of rules and tabs.
  • BETA 2: Fixed a bug where “rule messages” did not show for readonly fields.
  • BETA 2: Fixed a bug in setting field value for a date only field when this is read only. It will now show date only and not date and time. Please note: You must also update spjs-utility.js to v1.200 or later.
Get the BETA version here

Follow this link, and ensure you get the latest version. PS: The files are uncompressed, therefore the files are bigger than the production release.

Give feedback in the forum

Please post any findings or questions regarding the 4.210 BETA in this topic in the forums.

Unfortunately I have not been able to test this as thoroughly as I wanted, but I could not wait any longer to make it available. Post any findings to the forum, and I will fix the issues as soon as I can manage.

The more of you that gives feedback, the faster the production version will be released!

Best regards,

KPI for SharePoint 2010 and 2013

I received a question about the built in KPI in SP 2010. The user added the KPI to a list view that was filtered with a Query String Filter, but the KPI didn’t respect the filter and kept calculating based on the unfiltered view.

I don’t know if you can do anything about the built in KPI, but It’s a good opportunity to write some JavaScript!

Here is a solution you can drop in any list view to create a KPI that respects both Query String Filters and filters applied by the end user to the columns. The solution requires SP 2010 or 2013 (foundation or server), as it uses the JavaScript Client Object Model. It does NOT require jQuery.


Get the code for the file “SPJS-KPI.js” from here

Upload it to a document library where all users have read access, and add a HTML Form Web Part with this code in the list view or the web part page:

<table cellpadding="3" cellspacing="0">
	<tr style="font-size:24px;">
		<td valign="middle">KPI attached to list view:</td>
		<td valign="middle" id="kpi_1" style="height:55px;"><img style="margin:12px;" src="/_layouts/images/hig_progcircle_loading24.gif"></td>	

<script type="text/javascript" src="/SPJS/SimpleKPI/SPJS-KPI.js"></script>
<script type="text/javascript">

	// KPI example 1
	var args = {
		// Placeholder for the KPI must be an existing HTML element in the page with this ID
		// Target list and base URL
		// Target view - must be filled in to use "consumeFiltersFromList"
		// URL Filter
		// KPI Indicator field and value
		// Text
		"noFilterMessage":"The URL filter \"{0}\" is missing.",
		"noItemsFoundMessage":"No items match the filter",
		// Threshold
		// Icons
}, "sp.js");

Update the link to the file “SPJS-KPI.js” in the code example.

Variables explained
  • placeholderID: This is the ID of a HTML element in the page where you want the KPI to appear.
  • listGUID: This is the list GUID of the list you want to attach the KPI to. If you are using a list view from the list itself (not a web part page), you can use the variable from the example. If not, add the GUID to the list here. To find the GUID, go to a list view, right click and view source. Look for “pageListId”.
  • listBaseUrl: If the KPI list is in the same site, use the variable from the example. If not, add the path like this: “/Sites/NameOfTheSite”
  • consumeFiltersFromViewGUID: To have the filter consume the filters from a list view, add the GUID of the view you are applying the filter to here. Find the list GUID by filtering the view and look at the URL. In SP 2010 you see “View=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”, in SP 2013 you see it like this: InplviewHashxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. The GUID is where the x’es are.
  • URLfilterKey: If you are using an URL filter, this is the key from the URL like this: …/AllItems.aspx?key=value
  • URLfilterTargetField: This is the FieldInternalName of the field in the list where the filter is applied.
  • kpiIndicatorField: This is the FieldInternalName of the field you calculate the KPI from.
  • kpiIndicatorFieldValue: This is the value found in the field you calculate the KPI from. If it is a Yes/No column, use boolean value true or false.
  • greenThreshold: The percentage needed to show the green icon.
  • yellowThreshold: The percentage needed to show the yellow icon (the rest is red).
  • greenIcon, yellowIcon and redIcon: URL to the images.

Ask if you need help or you find a bug.