Category Archives: SharePoint 2007

Dynamic Forms for SharePoint: Production

Change log:

13.08.2012 You find an updated version here.


04.06.2012 After a few bugfixes, the current release is now v1.2.3.


02.06.2012 V1.2.1 fixes another set of bugs – here are the detail from the change log:

  • Fixed a bug that occurred when an identical rule was applied for multiple options in a single choice field (select or radio). This made the rules cancel eachother out.
  • Small update to the function “hideFields” to prevent hiding an empty required field (where the required flag was set in the list settings).
  • Another small update to the function “doReadOnly” to prevent the width of the “formlabel” to vary when toggling readonly for a field.

31.05.2012 V1.1 fixes a possible bug occurring when the Title-field is not present in the form.


Overview

This solution will let you add dependent logic to your forms:
IMG

For example you could have a Yes/No check box determines whether some fields as required or not, or the status selector in a Tasks list can toggle which fields are visible or read only when you change from “In progress” to “Completed”.

All screenshots are from SharePoint 2010, but this solution is designed for both SharePoint 2007 and SharePoint 2010. I have tested it in IE7, IE9, FireFox 12.0 and Google Chrome 19.0.1084.52, but not extensively, so please let me know if you experience problems.

I have previously posted a BETA version of this solution, but I have finally updated the Dynamic Forms for SharePoint solution to a “production release”.

Changes from the previous BETA version:
  • You can use the solution in DispForm
  • You can clone a rule, or clone the setup from NewForm to EditForm / DispForm
  • You can use a date column as trigger – though only [today] will work in this version.
  • Rich text column validation now works.
  • You can use multiple trigger values (options within same column) for one rule
  • You can check for group membership and execute rules if a user is NOT member in the group.
  • No more problems using “is not equal to”.

This article will walk trough the features and the setup of the updated version. I have added this as a separate article to keep it tidy.

Download files

Download the file “DynamicFormsForSharePoint.js” and “spjs-utility.js” from here. Please note that you will need the version dated 18.01.2012 or newer of “spjs-utility.js”. You find the files in folders with corresponding names.

You also need jQuery – download it here. You may use the latest version, but i prefer v1.6.4 as it is faster in some areas. You can not use jQuery versions below 1.6. Please note that not all of my other solutions will work with jQuery v1.7x.

Put these files in a document library or a folder created with SharePoint Designer. Ensure all users have read access to this location.

How to set up the solution

This solution is set up by referring a script from NewForm, EditForm and DispForm of the lists where you want the solution activated.

Add a CEWP to NewForm, EditForm and DispForm like this:

SharePoint 2007
Go to NewForm and EditForm and edit the URL by adding toolpaneview=2 behind the URL in this format:
…/NewForm.aspx?toolpaneview=2
…/EditForm.aspx?ID=12&toolpaneview=2
…/DispForm.aspx?ID=12&toolpaneview=2

Press Enter and you should be able to add a CEWP to the page. Put the CEWP below the form web part.

SharePoint 2010
In the list view, click “List” on the List Tools menu. Then select “Form Web Parts” and pick the form to add a CEWP to the page. Put the CEWP below the form web part.

I recommend using the Content link option in the CEWP to refer the code like the example below. The CEWP code should be put in a text file (txt) or an aspx file like in the example below. This file should be put in the same location as the file “DynamicFormsForSharePoint.js”.

CEWP setup in SharePoint 2010:
IMG

You could also put the code directly in a HTML Form web part as this web part is handled in a slightly different manner in SharePoint 2010, and therefore does not mess with the script generated HTML.

The CEWP code
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="/test/Scripts/DynRequired/spjs-utility.js"></script>
<script type="text/javascript" src="/test/Scripts/DynRequired/DynamicFormsForSharePoint.js"></script>

You must change the script src to all files so that they refer your local files.

These three scripts are all that goes in the CEWP – all configuration is done in a graphical user interface.

Behind the scenes

When this solution is first setup in a site, the configuration list is created automatically. This list is not to be hand edited, and it can be hidden using SharePoint Designer if you like.

When you configure the solution for a specific NewForm, EditForm or DispForm, the configuration is stored using the site-relative URL of the form as an identifier. When a user loads the form in a browser, this configuration is read from this location and the rules are applied “on the fly”.

How to configure the solution
Note on required fields
If you set a field as required in the list settings, and then hides it due to a rule when it’s still empty, the user will not be able to save the form.

When the solution is set up correctly, the only thing giving it away is the text “Dynamic Forms for SharePoint” in the bottom left corner of the form:
IMG
You click this text to enter the configuration. Note that this text number is visible only if the solution has not yet been configured for that form, or the logged in user is the one that configured the solution for this particular form in the first place.

You can however enter the edit mode manually by appending to the URL like this:
NewForm.aspx?dfsetup=1
EditForm.aspx?ID=10&dfsetup=1
DispForm.aspx?ID=10&dfsetup=1

If you set up a password protection for the configuration, you are prompted for the password when entering the edit mode:
IMG
This dialog is bypassed if a password has not been set.

You then enter the configuration:
IMG
Note that in DispForm, the only configurable setting is “These fields are hidden”. Hover the mouse over this image IMG in the GUI to get some hints on how to set up the rules for each field type.

You can use these field types as “triggers”:
Yes/No, Drop-Down Menu, Radio Buttons, Checkboxes (allow multiple selections), Single line of text, Number, Currency and Date and Time.

You can use the following operators to match their value

  • is equal to
  • is not equal to
  • is greater than
  • is less than
  • is greater than or equal to
  • is less than or equal to
  • begins with
  • contains

Not all operators can be used for all field types.

In addition to the fields, you can use *NOT member* in SharePoint group as trigger

Configuration options
Cloning rules from another form

When you have configured one form – like NewForm – you can clone the setup to another form in the same list. If you enter setup for EditForm, and you have already configured NewForm, you get this prompt:
IMG

If you press OK, you are presented with a list of already configured forms in the current list:
IMG

Multiple values in “This Value” field

You can have multiple values triggering the same rule. Add the values separated with the pipe character like this:
IMG

Yes/No fields

To configure a rule for a field of type “SPFieldBoolean” (Yes/No checkbox), you must enter a different value in NewForn / EditForm than in DispForm.
In NewForm and EditForm use true for checked and false for unchecked.
In DispForm use whatever text value representing “Yes” and “No”.

Apply rule by *NOT group membership*

You can apply a rule based on the user NOT being member in a specific group or groups (separate multiple ID’s with the pipe character):
IMG
Note that the operator dropdown is disabled.

To find the group ID, go to Site Actions > Site Settings > People and groups and click on the group name.

Look at the URL to find the group ID:
http://www.contoso.com/_layouts/people.aspx?MembershipGroupId=145

Updating from a previous version?

If you are updating from v0.9.1 or v0.9.2 I’m fairly sure all you have to do is to enter the configuration for your form, and save it again. I might be wrong, so post any bugs below.


Post any bugs or feature requests below.
Alexander

Show field description in list view column header – updated version

I have previously posted this solution that lets you add the field description to the list view column header.

By request I have updated the solution to work in a web part page with multiple lists / libraries.

Put this code in a Content Editor Web Part at the bottom of your list view or web part page:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
var is2010 = typeof(_fV4UI)!=='undefined';

$("div[id^='WebPartWPQ']").each(function(){	
	var wpID, tCtxId, tCtx, myTooltipObj, toFind, fieldDisplayName
	wpID = $(this).attr('WebPartID').toUpperCase();	
	tCtxId = g_ViewIdToViewCounterMap["{"+wpID+"}"];
	if(tCtxId!==undefined){
		tCtx = eval("(ctx"+tCtxId+")");	
		myTooltipObj = customGetList(tCtx.listName);	
		toFind = "table.ms-listviewtable th";
		if(is2010){
			toFind = "div.ms-vh-div";
		}		
		$(this).find(toFind).each(function(){
			if(is2010){
				fieldDisplayName = $(this).attr('DisplayName');	
			}else{
				fieldDisplayName = $(this).find("table:first").attr('DisplayName');	
			}
			if(fieldDisplayName===undefined){
				fieldDisplayName = $(this).text();
			}
			if(myTooltipObj[fieldDisplayName]!==undefined){
				$(this).attr('title',myTooltipObj[fieldDisplayName]).find('a').attr('title',myTooltipObj[fieldDisplayName]);;
			}
		});
	}
});

function customGetList(listName){
	var xmlWrap, result;
	xmlWrap = [];
	xmlWrap.push("<?xml version='1.0' encoding='utf-8'?>");
	xmlWrap.push("<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>");
	xmlWrap.push("<soap:Body>");
	xmlWrap.push('<GetList xmlns="http://schemas.microsoft.com/sharepoint/soap/">');
	xmlWrap.push('<listName>' + listName + '</listName>');
	xmlWrap.push('</GetList>');
	xmlWrap.push("</soap:Body>");
	xmlWrap.push("</soap:Envelope>");
	result = {};
	$.ajax({
		async:false,
		type:"POST",
		url:L_Menu_BaseUrl + '/_vti_bin/lists.asmx',
		contentType:"text/xml; charset=utf-8",
		processData:false,
		data:xmlWrap.join(''),
		dataType:"xml",
		beforeSend:function(xhr){
			xhr.setRequestHeader('SOAPAction','http://schemas.microsoft.com/sharepoint/soap/GetList');
		},
		success:function(data){
			$('Field', data).each(function(i){
				if(result[$(this).attr('DisplayName')]===undefined || result[$(this).attr('DisplayName')]===''){
					result[$(this).attr('DisplayName')] = ($(this).attr('Description')===undefined)?'':$(this).attr('Description');
				}
			});
		}
	});
	return result;
}
</script>

If you like this solution, buy me a beer!

Alexander

Showing or hiding form fields based on membership in a SharePoint group

This solution will let you control the visibility of individual fields in NewForm, DispForm and EditForm based on membership in a specific SharePoint group.

This is an updated version of this post.

I have updated it to support newer versions of jQuery, and to use spjs-utility.js.

Note:
If you plan to hide empty fields in NewForm or EditForm, these fields cannot be required to contains information as the user would not be able to save the form – and as the field is invisible, the user will not see the empty field validation message.
How to set up this solution:
  • Download the latest version of spjs-utility.js, and save it locally. You can put it in a folder created using SharePoint designer, or in a shared document library where all users have read permission.
  • If you prefer to use a local version of jQuery, get it here and save it alongside the file above.
  • Add the below code to a CEWP or a HTML form web part, and update the script src to reflect your local copy of spjs-utility.js and jQuery.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://files.spjsworks.com/files/spjs-utility/07.03.2012/spjs-utility.js"></script>
<script type="text/javascript">

var fields = init_fields_v2();
// The group ID
var groupId = 146; // This number must be changed to match your local group ID
// Show this array for members in the above group
var arrToShowForMembersInTheGroup = ['Title','ForOwnersOnly'];
// And this array for everybody else
var arrToShowForEverybodyElse = ['Title'];

var isInGroup = isCurrentUserInGroup(groupId,false);
if(isInGroup){
	hideAllButThese(arrToShowForMembersInTheGroup);
}else{
	hideAllButThese(arrToShowForEverybodyElse);
}

/************************************
     Do not edit below this line
************************************/
function isCurrentUserInGroup(groupId,returnGroupName){
	var ui, userLoginName, ug, result;
	ui = getUserInfo_v2(_spUserId); 
	userLoginName = ui['Name'];
	ug = getGroupCollectionFromUser(userLoginName);
	result = false;	
	$.each(ug,function(i,obj){
		if(obj.groupId===groupId){
			if(returnGroupName){
				result = obj.groupName;
			}else{
				result = true;
			}
			return false;			
		}
	});
	return result;
}

function getGroupCollectionFromUser(userLoginName,userListBaseUrl){
	if(userListBaseUrl===undefined){
		userListBaseUrl = L_Menu_BaseUrl;
	}
	var result = [];
	spjs_wrapSoapRequest(userListBaseUrl + '/_vti_bin/usergroup.asmx', 
		'http://schemas.microsoft.com/sharepoint/soap/directory/GetGroupCollectionFromUser',
		'<GetGroupCollectionFromUser xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/"><userLoginName>' + userLoginName + '</userLoginName></GetGroupCollectionFromUser>',
		function(data){		
			$('Group', data).each(function(idx, itemData){
				result.push({"groupId":parseInt($(itemData).attr('ID'),10),"groupName":$(itemData).attr('Name')});
			});
		});
	return result;
}

function hideAllButThese(arrToShow){
	$.each(fields,function(fin){
		if($.inArray(fin,arrToShow)===-1){
			$(fields[fin]).hide();
		}else{
			$(fields[fin]).show();
		}
	});	
}
</script>
How to configure the solution

Find the group ID of the group you want to use by going to Site Settings > People and Groups, select your group and look at the URL:
http://www.contoso.com/_layouts/people.aspx?MembershipGroupId=6

Change the FieldInternalNames in the array “arrToShowForMembersInTheGroup” and “arrToShowForEverybodyElse” to match your setup.

Look here to learn how to manually retrieve FieldInternalNames, or here to find a solution that shows you all in one go.

If you have trouble, post a comment below.

Alexander

SPJS Resource Management – No more double booking

I got this request from Cory

Alexander,

I was curious if you’d be interested in brain-storming a javascript idea for SharePoint calendars?
I’d be more than happy to buy you a couple beers to support it… 🙂

Here is what I was looking at doing.

1. Using Javascript, validate a new (or edited) calendar entry prior to save.
2. The save will check for overlapping dates and/or times.
3. The save could (if possible) validate pre-blocked times for either allowing entries or disallowing entries.

Real-world example.

We have an appointment calendar. I envision having within the same calendar (or for the sake of organization) in a seperate calendar,entries of what days and times are allowed to be “booked” and/or entries of days and times that are block from being “booked”

When a user attempts to create a new entry, the “booking” layer is evaluated to see if this new entry violates any of the currently exisiting rules. If it does, a notice is displayed.
Next, the new entry will be evaluated if it violates any currently exisiting entries. If it does, a notice will be displayed.

Do you think this might be possible via Javascript and/or SP Services?

Thanks!


The solution

I have made a solution that lets you set the time period of each week day that a resource (like a meeting room) can be booked. This is done by specifying a choice field (Meeting room) in the setup of this solution, and to add records in the settings list for each selection in the choice field (like Meeting room 1 or Meeting room 2).

This solution will ensure the room can be booked in the available time period only, and will also prevent users from double booking the resource by checking for overlapping time periods before saving the new or edited record.

The user will be presented with informative messages regarding time period or dates out of range, and/or double bookings so they can correct their input before attempting another save.

This solution is designed for both SharePoint 2007 and SharePoint 2010.

Here is a few screenshots before we walk trough the setup
IMG

In this example, Team 1 has booked room 1 for their morning meeting:
IMG

Then Team 2 tries to book the same room for a sales meeting:
IMG

The setup
  1. Download the latest version of “spjs_utility.js” from here
  2. Download the file “SPJS-ResourceManagement.js” and the CEWP code from here
  3. Upload “spjs_utility.js”, “SPJS-ResourceManagement.js”, jQuery and jQueryUI (if you prefer a local copy), to a shared document library, or a folder created in SharePoint Designer. Ensure all user have read access to the location where you put the files.
  4. Change the variables in the top of the CEWP code, and the script src to jQuery, jqueryUI, the jQueryUI css file, “spjs-utility.js” and “SPJS-ResourceManagement.js” to reflect your local copies.
  5. Upload the CEWP code as a txt file to the same location as the other files.
  6. Add a CEWP below the form web part in NewForm.aspx / EditForm.aspx and use the “content link option” to link to the CEWP code you uploaded in the previous step. You may also use the HTML form web part and put the CEWP code in the “source editor” directly.
  7. Enter edit mode by clicking the © below the form in NewForm.aspx.
  8. You may supply a password in the GUI to prevent user from editing the settings.

When you first enter the edit mode, you are prompted to create the configuration list:
IMG
Click “OK” to create it:
IMG
You will never have to hand edit the configuration list, but you find it under “All Site Content” of the site you specify as “SPJSRM_settingsListBaseUrl” in the CEWP code.

This is PARTS of the CEWP code
There are also a chunk of HTML code that must be included. You find the complete code in the download referred above.

<link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/sunny/jquery-ui.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<script type="text/javascript" src="/test/Scripts/spjs_utility - blog/spjs-utility.js"></script>
<script type="text/javascript" src="/test/Scripts/SPJSResourceManagement/SPJS-ResourceManagement.js"></script>
<script type="text/javascript">
var SPJSRM_listName = "SPJSRM"; // Preferably use the List GUID
var SPJSRM_settingsListBaseUrl = L_Menu_BaseUrl; // The base url of the settings list
var SPJSRM_resourceFieldInternalName = "MeetingRoom"; // the FieldInternalName of the choice field that holds the name of the resources
var timeFormat = 24; // 12 for 12 Hour format or 24 for 24 Hour
// Validation messages
var alreadyBookedMsg = "This resource can be booked between {0} and {1}";
var overlapMsg = "The selected time period is not available. It has been booked by {0} between {1} and {2}.";
var endBeforeStartMsg = "End time cannot be less than or equal to start time.";
var startDateOutOfRange = "{0} is out of range.nnStarting date cannot be prior to {1}.";
var endDateOutOfRange = "{0} is out of range.nEnd date cannot be after {1}.";
</script>

These are the primary variables that needs attention

  • SPJSRM_listName: This is the list GUID or the DisplayName of the list you want this feature to apply to. In SharePoint 2010 you can use the variable “_spPageContextInfo.pageListId”, but for SharePoint 2007 you must find the GUID as described here
  • SPJSRM_settingsListBaseUrl: This is the base url of the settings list. Use “L_Menu_BaseUrl” to refer the current site, or supply another baseUrl to place the configuration list in another site – use “” to refer the root site.
  • SPJSRM_resourceFieldInternalName This is the FieldInternalName of the choice field that holds the name of the resources. Go here to learn how to find the FieldInternalName for a field
  • timeFormat: Use 12 for 12 Hour format or 24 for 24 Hour. Only cosmetics regarding the time as displayed in validation messages.


Buy me a beer!
If you like the solution – buy me a beer!

Form Field Tooltip for SharePoint 2007 and SharePoint 2010

27.01.2013 Updated to v1.5 and added MUI support.


30.04.2012 Updated the solution to Move the tooltip image to the formlabel field and ensured all fields are visible when entering “fftsetup=1”.


26.02.2012 Updated the solution to prevent cutting the top of large tooltip containers.


I have previously posted a solution for adding HTML tooltip for selected fields in a SharePoint form. Your find it here.

This is an updated version that is easier and cleaner – and it supports both SharePoint 2007 and SharePoint 2010.


Hover over the image to preview the tooltip
IMG

Add “fftsetup=1” to the URL to enter edit mode
For NewForm: /Lists/MyList/NewForm.aspx?fftsetup=1
For DispForm: /Lists/MyList/DispForm.aspx?ID=12&fftsetup=1
For EditForm: /Lists/MyList/EditForm.aspx?ID=12&fftsetup=1

You then enter edit mode
IMG

Wrap the tooltip text/HTML in a div with a width attribute like this:

<div style="width:200px">
   The tooltip text/HTML goes here
</div>

Or you can set a fixed width in the CEWP code under the style for “tooltipHolder” – see CEWP code example below.

How to set it up
  1. Download the latest version of “spjs_utility.js” from here
  2. Download the file “SPJS-FormFieldTooltip.js” and the CEWP code from here
  3. Upload “spjs_utility.js”, “SPJS-FormFieldTooltip.js” and jQuery (if you prefer a local copy), to a shared document library, or a folder created in SharePoint Designer. Ensure all user have read access to the location where you put the files.
  4. Change the three variables in the top of the CEWP code, and the script src to jQuery, “spjs-utility.js” and “SPJS-FormFieldTooltip.js” to reflect your local copies.
  5. Upload the CEWP code as a txt file to the same location as the other files.
  6. Add a CEWP below the form web part in NewForm.aspx / DispForm.aspx / EditForm.aspx and use the “content link option” to link to the CEWP code you uploaded in the previous step. You may also use the HTML form web part and put the CEWP code in the “source editor” directly.
  7. Enter edit mode by appending “fftsetup=1” in the URL as described above.

This is the CEWP code

<script type="text/javascript">	
	var settingsListBaseUrl = L_Menu_BaseUrl;
	var thisListID = "mylist";
	var hoverImgPath = "/_layouts/images/hhelp.gif";
</script>
<style type="text/css">
img.customTooltip{
	float:right;
	cursor:pointer;
}
td.toolTipEditor{
	vertical-align:top;
	padding:5px;
	background-color:#DFFFA5;
}
textarea.tooltipTextarea{
	height:150px;
	width:300px;
}
#tooltipHolder{
	background-color:#feeebd;
	padding:5px;
	border:1px silver solid;
	display:none;
	/*width:200px;*/
	-moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    -khtml-border-radius: 10px;
    border-radius: 10px;
}
</style>
<div id="tooltipHolder"></div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="/spjs-utility/24.02.2012/spjs-utility.js"></script>
<script type="text/javascript" src="/test/Scripts/TooltipV2/SPJS-FormFieldTooltip.js"></script>

You must change these variables:

  • settingsListBaseUrl: This is the baseUrl to the site where the configuration list should be created. Use the variable L_Menu_BaseUrl to refer the current page.
  • thisListID: This is the unique id of the list you want the tooltip to appear in. If you plan to use the solution for multiple lists in one site, this value must be unique for each list as it’s this value that identifies which tooltip is for which list.
  • hoverImgPath: This is the path to the image the user hovers over to preview the tooltip.

When you first enter setup, you are presented with this prompt
IMG

Hit “OK” to create the list. You will get this “receipt”
IMG


You will never have to hand edit the configuration list, therefore I have not said a whole lot about it…


Buy me a beer!
If you like the solution – buy me a beer!

Alexander

List inspector – Ed MacIntosh

I received this code from one of my readers – Ed MacIntosh with this message:

Alex,
This is a great web part that someone at my company shared that I think your readers would really find useful.
It provides a dropdown menu to choose a list in your site and upon selection displays the field name as next to the filed internal name for all fields in the list.

You drop it in a CEWP and it will let you pick any list in your site collection to list all columns by “DisplayName”, “FieldInternalName” and “FieldType” like this:
IMG

The only thing I have changed is the style of the table to “width:auto”, so all credit goes to Ed and his colleague.

&lt;select id=&quot;spLists&quot; onchange=&quot;displayFieldData(this.options[this.selectedIndex].value)&quot;/&gt;
&lt;div id=&quot;spListsSelected&quot;&gt;&lt;/div&gt;
&lt;table id=&quot;spListFieldTable&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;width: auto&quot;&gt;&lt;/table&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var siteURL = 'http://' + window.location.host + L_Menu_BaseUrl + '/_vti_bin/lists.asmx';
$(document).ready(function(){
	var soapEnv = &quot;&lt;soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'&gt; 
					&lt;soap:Body&gt; 
					&lt;GetListCollection xmlns='http://schemas.microsoft.com/sharepoint/soap/' /&gt; 
					&lt;/soap:Body&gt; 
					&lt;/soap:Envelope&gt;&quot;;
	$.ajax({
		url: siteURL,beforeSend: function(xhr) {
			xhr.setRequestHeader(&quot;SOAPAction&quot;,
			&quot;http://schemas.microsoft.com/sharepoint/soap/GetListCollection&quot;);
		},
		type: &quot;POST&quot;,
		async: false,
		dataType: &quot;xml&quot;,
		data: soapEnv,
		complete: processResult,
		contentType: &quot;text/xml; charset=&quot;utf-8&quot;&quot;
	});
});

function processResult(xData, status) {
	$(&quot;#spLists&quot;).append(&quot;&lt;option&gt;Select a List&lt;/option&gt;&quot;);
	$(xData.responseXML).find(&quot;List&quot;).each(function() {
	var liHtml = &quot;&lt;option value='&quot; + $(this).attr(&quot;Title&quot;) + &quot;'&gt;&quot; + $(this).attr(&quot;Title&quot;) + &quot;&lt;/option&gt;&quot;;
	$(&quot;#spLists&quot;).append(liHtml);
	});
}

function displayValue(splistname) {
	$(&quot;#spListsSelected&quot;).text(splistname); 
}

&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var arrSkipFieldTypesOf = ['Computed'];
var arrIncludeOverrideFields = ['Title','Author','Created','Modified','Editor'];
function displayFieldData(listname) {
	if(listname == &quot;&quot; || listname == undefined) return false;
	var soapEnv = &quot;&lt;soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'&gt; 
					&lt;soap:Body&gt; 
					&lt;GetList xmlns='http://schemas.microsoft.com/sharepoint/soap/'&gt; 
					&lt;listName&gt;&quot; + listname + &quot;&lt;/listName&gt; 
					&lt;/GetList&gt; 
					&lt;/soap:Body&gt; 
					&lt;/soap:Envelope&gt;&quot;;
	$.ajax({
		url: siteURL,
		beforeSend: function(xhr) {
		xhr.setRequestHeader(&quot;SOAPAction&quot;,
		&quot;http://schemas.microsoft.com/sharepoint/soap/GetList&quot;);
		},
		type: &quot;POST&quot;,
		async: false,
		dataType: &quot;xml&quot;,
		data: soapEnv,
		complete: processResult2,
		contentType: &quot;text/xml; charset=&quot;utf-8&quot;&quot;
	});
}

function processResult2(xData, status) {
	$(&quot;#spListFieldTable tr&quot;).remove();
	$(&quot;#spListFieldTable&quot;).append(&quot;&lt;tr style='font-weight:bold;'&gt;&lt;td style='padding-right:10px'&gt;DisplayName&lt;/td&gt;&lt;td style='padding-right:10px'&gt;FieldInternalName&lt;/td&gt;&lt;td style='padding-right:10px'&gt;FieldType&lt;/td&gt;&lt;/tr&gt;&quot;);
	$(xData.responseXML).find(&quot;Field&quot;).each(function() {
		if (($.inArray($(this).attr('Name'),arrIncludeOverrideFields)&gt;-1) || ($(this).attr('FromBaseType')!='TRUE' &amp;&amp; $(this).attr('Sealed')!='TRUE' &amp;&amp; $(this).attr('DisplayName')!=undefined &amp;&amp; $.inArray($(this).attr('Type'),arrSkipFieldTypesOf)==-1)) {
			var trHtml = &quot;&lt;tr&gt;&quot;;
			trHtml += &quot;&lt;td style='padding-right:10px'&gt;&quot; + $(this).attr(&quot;DisplayName&quot;) + &quot;&lt;/td&gt;&quot;;
			trHtml += &quot;&lt;td style='padding-right:10px'&gt;&quot; + $(this).attr(&quot;Name&quot;) + &quot;&lt;/td&gt;&quot;;
			trHtml += &quot;&lt;td style='padding-right:10px'&gt;&quot; + $(this).attr(&quot;Type&quot;) + &quot;&lt;/td&gt;&quot;;
			trHtml += &quot;&lt;/tr&gt;&quot;;
			$(&quot;#spListFieldTable&quot;).append(trHtml);
		}
	});
	$(&quot;#spListFieldTable tr:odd&quot;).css(&quot;background-color&quot;,&quot;rgb(206,206,206)&quot;);
}
&lt;/script&gt;

Alexander

SPJS Charts for SharePoint v3.x

10.12.12 I introduced a new bug in v3.3.7 that broke the filter if you did NOT use “filterAdditionalCharts”. This should be fixed in v3.3.8.


13.11.2012 Updated to v3.3.7 to fix a bug regarding “filterAdditionalCharts” in the Custom CAML filter setup. This was broken in v3.3.6 – thanks to Paul Brown for notifying me.

Please note that you now have to supply the parameter for each filter in the filter setup. Click the “Instructions” link above the filter setup textarea for details.


20.09.2012 Updated to v3.3.5
06.09.2012 Updated to v3.3.1. This update is an attempt to fix an issue where you apply multiple formatters on the same column, and only the last one sticks.
18.07.2012: Updated to v3.3 and added a few new features. See this article for details.
07.06.2012: Updated to v3.2.2 to add support for special characters like single quote and “&” in the filter options. See change log.
29.05.2012: Updated to v3.2.1 to fix a bug. See change log.
31.03.2012: Updated to v3.2.
Added filter wildcard to allow “Show all” when using dropdown filter. See “Filter setup Instructions” in the “Edit chart GUI”.
See change log for details on some small bugfixes.
21.02.2012: Updated to v3.1.5. See change log.
14.02.2012: Updated to v3.1.4. See change log.
13.02.2012: Updated to v3.1.3. See change log.
06.02.2012: Updated to v3.1.2. See change log.


06.02.2012: Updated to v3.1.1 to avoid using eval. Read more in the article. Thanks to Christophe for pointing me to the “jQuery.parseJSON()” method – I was not aware that jQuery had this built in.


This article will freshen up on the setup of the solution and will describe the changes in v3.1

Keywords: New chart types, multiple dropdown filters and variables in the custom CAML query.


I have “silently” released version 3 of the “Charting for SharePoint using Google Visualization API” solution in November 2011. You find it here. The 3.0 release was not so mush about new functionality, but focused more on tidying up the GUI to make it easier for the user to understand the configuration options.

In the work with v3.0 i realized that i did not have any distinct name for the solution, and I decided to name the solution SPJS Charts for SharePoint.

A full walktrough of the configuration options in v3.0 can be found in this book from O’Reilly. The book is a collection of articles from Nothing But SharePoint. The article you find in this book (Publication Date: February 24, 2012) has not been published elsewhere.
The setup

To start using this solution, you only need the rights to create a list (will be done automatically by this solution), upload files and add a CEWP or a HTML form web part to a page.

After the initial setup, all you need is contribute rights to edit charts.

The setup process contains four steps:

  1. Download the file “SPJS_ChartsForSharepoint_v3.x.js” and “CEWP.txt” from here from here. You can choose between the uncompressed (124KB) “SPJS_ChartsForSharePoint_v3.1.js” and the packed, smaller version version (64KB) “SPJS_ChartsForSharePoint_v3.1_min.js”. The latter is packed using packer. You find the CEWP code and the script file in separate folders. The folder name will reflect the script version. Ensure you download the latest version, and that you read the change log.
  2. Upload the file “SPJS_ChartsForSharepoint_v3.x.js” to a document library, or put it in a folder created with SharePoint Designer for safer storage. Ensure all users have read access to the file.
  3. Copy the link to the file “SPJS_ChartsForSharepoint_v3.x.js” and replace the example path in the CEWP code so that it reflects your local copy.
  4. Either upload the CEWP code to the same folder as the file “SPJS_ChartsForSharepoint_v3.x.js” and use the content link option in a CEWP to link to the code, or use a HTML form web part and insert the code directly in the “Source editor”.

Reload the page, and if it is the first time it is run in the site, the solution will prompt you to create the configuration list. If you are upgrading from an earlier solution, you are prompted to update the configuration list. Both actions require no more than a click on the OK button to complete.

If you are upgrading AND you have a multi language setup:
Ensure you have selected the “native” language for the site collection before you complete the update of the configuration list. If you fail to do so, the update will not take effect and the prompt will not go away.
These are the changes in v3.1
Chart types

Switched GeoMap for GeoChart and added BubbleChart and SteppedAreaChart.

Dropdown select filters

In the previous versions, you could create ONE dropdown filter above the chart. In v3.1 you can have multiple. The setup of the filter have changed, and those updating from a previous version will have to redo the filter setup (you will get an error message telling you that the filter setup is wrong).

IMG
The chart example above has this filter setup to create the “Year dropdown”:

IMG
You can have multiple filters created in the same way, Click “Instructions” above the Filter setup textarea to expand this description:

Use an object literal like this:
[{“label”:”Year”,”urlKey”:”year”,”options”:[{“f”:”2011″,”v”:”2011″},{“f”:”2012″,”v”:”2012″,”selected”:true}]},{“label”:”Status”,”urlKey”:”status”,”options”:[{“f”:”Not started”,”v”:”0″},{“f”:”In progress”,”v”:”1″,”selected”:true}]}]

The object properties:
label: The label in front of the dropdown.
urlKey: The parameter in the url that identifies the value.
f: Friendly name for the option. Can be the same as “v”.
v: Internal name for the option. Can be the same as “f”.
selected: true if the option should be preselected.

When you have written or prefilled the filter (by selecting it from the “Prefill textarea from choice field-dropdown”), you must add the appropriate CAML in the “Custom CAML-query” textarea. You can start by clicking “Build CAML from selected filters” below the Custom CAML-query textarea to have the raw CAML autogenerated.

Note that you must change the text “FieldInternalNameToMatch” in the Custom CAML-query textarea to the correct FieldInternalName.

The new filter method can use eval1, and thus you can have parts of, or even the complete filter as a variable in the CEWP. To do this, you create a variable in the CEWP code and inserts the variable name in the “Filter setup” textarea. Please note that the CAML is “static” and you must insert the corresponding {filter:urlKey} in the Custom CAML-query textarea to pick up the filters.

1. This feature has changed from v3.1 to v3.1.1 and must now be turned on (off by default) to allow “eval”. This is a security risk, but if you want to have the filter setup as a variable in the CEWP code, add this setting to the CEWP:

var allowEval = true;
Variables directly in the custom CAML

Another new feature is the ability to use variables directly in the CAML. Construct the variables in the CEWP code like an object named “spjsCAMLvariables”, then insert {variable:variable_name} in the Custom CAML-query textarea where you want the variable to be inserted. “variable_name” represents one property from the object “spjsCAMLvariables”.

In the following example i have used it to filter a calendar to show this weeks items.
In the CEWP code you insert code like this to get the two variables “thisWeekMonday” and “thisWeekSunday”:

// Get todays date
var today = new Date();
// Find monday in current week
while(today.getDay()!==1){
	today.setDate(today.getDate()-1); 
}
// Create two date objects - one for Monday and one for Sunday
var monday = new Date(today);
var sunday = new Date(today.setDate(today.getDate()+6));
// Convert the dates to ISO8601 format: yyyy-mm-dd for use in CAML
var thisWeekMonday = monday.getFullYear().toString()+&quot;-&quot;+(monday.getMonth()+1).toString()+&quot;-&quot;+monday.getDate().toString();
var thisWeekSunday = sunday.getFullYear().toString()+&quot;-&quot;+(sunday.getMonth()+1).toString()+&quot;-&quot;+sunday.getDate().toString();
// the object used in the Custom CAML-query
var spjsCAMLvariables = {&quot;thisWeekMonday&quot;:thisWeekMonday,&quot;thisWeekSunday&quot;:thisWeekSunday};

Insert the variables in the Custom CAML-query textarea like this:

&lt;Where&gt;
&lt;And&gt;
&lt;Geq&gt;
&lt;FieldRef Name='StartDate' /&gt;&lt;Value Type='DateTime'&gt;{variable:thisWeekMonday}&lt;/Value&gt;
&lt;/Geq&gt;
&lt;Leq&gt;
&lt;FieldRef Name='StartDate' /&gt;&lt;Value Type='DateTime'&gt;{variable:thisWeekSunday}&lt;/Value&gt;
&lt;/Leq&gt;
&lt;/And&gt;
&lt;/Where&gt;

Hit “Save” and your chart will always show the current weeks items.


The Google Visualization API team periodically releases a new version of the Google Visualization API. While the Visualization API team thoroughly tests each new version, bugs may still exist in any new release. You can test the release candidate before it becomes official by setting a variable in the CEWP code like this:

var loadRC = true;
Note on configuration option:
I have changed from “eval” to “jQuery.parseJSON” to handle the configuration options. The new method is a bit more picky on the syntax of the parameters and you must ensure to use double quotes and not single quotes for the option value.

Example:
Wrong syntax
colors:[‘red’,’#004411′]
Correct syntax
colors:[“red”,”#004411″]


If you use this solution, please consider buying me a beer!

Alexander

Dynamic Forms for SharePoint

29.05.2012 I have published a production release here

You can no longer leave comments in this article. Please post any comments or questions in the one linked above.


29.01.2012 I have done some work during this weekend, and i see that i have underestimated the complexity dealing with other than “is equal to” in this solution. I will see what i can do about that, and will post a new version as soon as i can manage. In the meantime, stick with “is equal to”.

Please note that this solution is under development – and is still BETA. I’m almost certain I’ll have to change the configuration options – and this will break the existing “filters”. Please bear this in mind when testing this solution.

Alexander


22.01.2012
I have redone the script due to some bugs in the initial release. It should still be considered as a “beta”, but i hope as many as possible can test it and let me know the result.

I have not added any functionality over the initial release as i want to ensure the parts already in it works as expected before doing so. I have however noted these requests:

  1. DispForm support
  2. Set field value / clear field value

Alexander


I posted a teaser for my latest project in December. Now I thought it was time to post a working solution!

This solution will let you add dependent logic to your forms.
For example you could have a Yes/No check box determines whether some fields as required or not, or the status selector in a Tasks list can toggle which fields are visible or read only when you change from “In progress” to “Completed”.

Please note that the initial release is set to v0.9. I expect you to find some bugs! Please test it and comment below if you find something wrong, or you have a feature request.

All screenshots are from SharePoint 2010, but this solution is designed for both SharePoint 2007 and SharePoint 2010. I have tested it in IE7, IE9, FireFox 9.0.1 and Google Chrome 16.0.912.75.

How to set it up

Download the file “DynamicFormsForSharePoint.js” and “spjs-utility.js” from here. Please note that you will need the version dated 18.01.2012 or newer of “spjs-utility.js”. You find the files in folders with corresponding names. You also need jQuery – download i here. You may use the latest version, but i prefer v1.6.4 as it is faster in some areas. Please note that not all of my other solutions will work with jQuery v1.7x.

Put these files in a document library or a folder created with SharePoint Designer. Ensure all users have read access to this location.

This solution is set up by referring a script from NewForm and EditForm of the lists where you want the solution activated.

Add a CEWP to NewForm and EditForm like this

SharePoint 2007
Go to NewForm and EditForm and edit the URL by adding toolpaneview=2 behind the URL in this format:
…/NewForm.aspx?toolpaneview=2
…/EditForm.aspx?ID=12&toolpaneview=2

Press Enter and you should be able to add a CEWP to the page. Put the CEWP below the form web part.

SharePoint 2010
In the list view, click “List” on the List Tools menu. Then select “Form Web Parts” and pick NewForm and Editform from there and add a CEWP to the page. Put the CEWP below the form web part.

I recommend using the Content link option in the CEWP to refer the code like the example below. The CEWP code should be put in a text file (txt) or an aspx file like in the example below. This file should be put in the same location as you put the file “DynamicFormsForSharePoint.js”. You could also put the code directly in a HTML Form web part as this web part is handled in a slightly different manner in SharePoint 2010, and therefore does not mess with the script generated HTML.

CEWP setup in SharePoint 2010
IMG

The code the file CEWP.js.aspx

&lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/Scripts/DynRequired/spjs-utility.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/Scripts/DynRequired/DynamicFormsForSharePoint.js&quot;&gt;&lt;/script&gt;

You must change the script src to all files so that they refer your local files.

These three scripts are all that goes in the CEWP – all configuration is done in a graphical user interface.

Behind the scenes

When this solution is first setup in a site, the configuration list is created automatically. This list is not to be hand edited, and it can be hidden using SharePoint Designer if you like.

When you configure the solution for a specific NewForm or EditForm, the configuration is stored using the site-relative URL of the form as an identifier. When a user loads the form in a browser, this configuration is read from this location and the rules are applied “on the fly”.

How to configure the solution

Note:
When manipulating required fields, you must NOT set the fields as required under list settings in SharePoint. Let this script handle it.

When the solution is set up, the only thing giving it away is the little version number in the bottom left corner of the form:
IMG
You click this version number to enter the configuration. Note that this version number is visible only if the solution has not yet been set up, or the logged in user is the one that configured the solution for this particular form in the first place.

You can however enter the edit mode manually by appending to the URL like this:NewForm.aspx?setup=1 or EditForm.aspx?ID=10&setup=1

If you set up a password protection for the configuration, you are prompted for the password when entering the edit mode:
IMG
This dialog is bypassed if there are no password.

You then enter the configuration:
IMG

You can use these field types as “triggers”:
Yes/No, Drop-Down Menu, Radio Buttons, Checkboxes (allow multiple selections) and Single line of text.

You can use the following operators to match their value

  • is equal to
  • is not equal to
  • is greater than
  • is less than
  • is greater than or equal to
  • is less than or equal to
  • begins with
  • contains
Example

The Configuration
IMG

This configuration will result i these changes to the form
IMG

IMG

IMG


Let me know if you get this solution working. I’ll update the article with any missing parts tomorrow, so please let me know if you find any bugs in the solution, or missing steps in the article.

Alexander