Archive
My CodePlex Projects – Now SharePoint 2010 Compatible #in
Just a quick note to say that my I have added my CodePlex projects to my blog and I have also tested them in SharePoint 2010.
I am pleased to say that they work without modification.
https://ghamson.wordpress.com/codeplex-projects/
I will also be updating this site with video showcases for each web part as I get round to doing them. (Probably start this weekend).
Let me know what you think.
Useful JavaScript Function: HTML Encode #in
Recently I have found the need to HTML Encode text in JavaScript, especially when using update list items and Single Line Of Text or Multiple Lines Of Text fields.
An easy way to do this is use the native functionality of the browser when it processes DIV’s.
Any text inside of a DIV automatically gets HTML Encoded. So all we have to do is create a DIV on the fly, insert the text and return the output.
1 function HTMLEncode(str) { 2 var div = document.createElement('div'); 3 var text = document.createTextNode(str); 4 div.appendChild(text); 5 return div.innerHTML; 6 }
Form Services / InfoPath 2010 Bug found in Multi-line Plain Text boxes
- Form Control: Text Box
- Read-only – No
- Enable spelling checker – Yes
- Enable AutoComplete – Yes
- Multi-line – Yes
- Height: Auto
- Form Type: Web Browser Form (2010)
- Browser: Internet Explorer 7, 8, Google Chrome
- Image Before:
- Image After:
- Browser: Firefox 3.6.10
- Before:
- After:
Showing the Version column in Office as a Quick Part (Office 2007 & 2010 / Document Field (Office 2003)
Recently in a project I have had the requirement to show the Version column within the Word document to aid document management at the company.
Why this isn’t standard functionality is anyone’s guess but this has been a “feature” of SharePoint since the beginning.
This post is going to concentrate on the various different methods available to solve this issue:
1. Use SharePoint Designer to copy the Version to a separate column
Although this works, when you open the document, the list data and the document version will be out of sync by one iteration. This is fine if you are opening the document in read-only, but will give the impression that you are overwriting the current version in editing mode.
Issues with this approach:
- The version will increase as the metadata gets updated via SharePoint Designer
- Unless you have “require checkout for editing turned off” you will run into problems in the logic around check in and check out. Ultimately it will also artificially increase the version of the document and if document approval is turned on you will never be able to publish the document. (Constant Draft state)
2. Using the Labels feature of SharePoint.
A blog post I have found suggests using the labels feature of SharePoint. This works but have limited formatting capabilities within the document template.
In particular, formatting must be set at the creation of the label on the server. This results in no formatting capabilities in the Word client apart from location of the label. It essentially creates an image on the fly when a user opens the document.
Unlike option 1 in this post, this does however work and doesn’t have adverse affects on the Version or Approval states.
Issues with this approach:
- Word 2007 or 2010 only (Office 2003 is not supported)
- How to achieve this result (taken from the blog post linked above:
- Enable versioning and content types on your document library.
- Go into document library settings and select the content types you want the version to appear in.
- Select Information management policies settings from the content type menu.
- Select define a policy and click .
- Click on the ‘Enable Label’ Check box
- Do not Check the other two boxes in the Labels section.
- In the Label Format field, enter the metadata fields in the following format:
Version : {Version} \n - Set the label appearance and click on preview.
- Click at the bottom of the page.
- Go back to the library and create a new document using the content type you have modified.
- Save the file as a Word 2007 format.
- Select the insert tab
- Select Quick Parts from the Ribbon menu and hover over document property
- Select Label from the properties list
- This should display the metadata defined in your label as a field in your word document. The field will update automatically when you next open the document.
- Save.
|
|
3. Event handler to copy the version to a separate field
Using the object model, to copy the version value on Check Out of the document and upon Check In of the document.
The object model allows you to check in using the existing version number, thus getting over the artificial creation of new versions, but you will need to take into account the end users version comments when you do this. as well as the approval process.
Luckily for use someone has created a solution for us and has made it open source. The solution is available for WSS 3.0, MOSS 2007 as well as SharePoint 2010 (Foundation and Server).
Compatibility is also available within all likely versions of Microsoft Office (2003, 2007 and 2010).
- Quick Parts (Office 2007, 2010)
- Fields (Office 2003)
- The solution handles Major and Minor Versioning as well as Content Approval within Document Libraries by adding the fields Current Version, Approval Version, Approval Date & Approval User.
- The only downside to this solution is that the above columns cannot be set to hidden within the content type as they will not appear in the Quick Part / Field options if this property is set.
- This results in extra fields in the Document Information Panel that end users can fill in if they desire. However this does not affect operation since the event handler overwrites the values when they fire on Check Out and Check In.
- The solution is available here: http://spversionindocs.codeplex.com/.
- So basically this solution is 99% perfect and I am not sure the only downside can be fixed without client side development (in Microsoft Word). This would cause its own headaches anyway.
As a result, this appears to be the best solution available and definitely recommend it to clients.
SharePoint Job Market
http://www.sharepointedutech.com/2010/10/13/a-sharepoint-recruiters-evaluation-of-the-jobs-market/
Very interesting article.
Office 2010 August Cumulative Update Descriptions
Hotfix descriptions for the whole Office 2010 suite including:
- SharePoint Foundation 2010
- SharePoint Server 2010
- Project Server 2010
Useful JavaScript Function: Hide Side Panel / Quick Launch – v4.master
On dashboard pages I often find I need more space. A quick way to do this is to place this into a Content Editor Web Part.
1 <script type='text/javascript'> 2 3 function v4MasterHideSidePanel() { 4 $('#s4-mainarea').children().eq(0).hide(); 5 $('#s4-mainarea').children().eq(1).css('margin-left', '0'); 6 } 7 8 $(document).ready(function(){ 9 v4MasterHideSidePanel(); 10 }); 11 12 </script>
This will hide the Side Panel / Quick Launch area on the v4.master – Master Page (Default Master Page for non-publishing sites)
NB: This method relies on JQuery
Useful JavaScript Function: Retrieve Query String Value
Quite often during my implementations I need to retrieve values from the query string to use as prefill values or perhaps redirect users to another page where I am using the Query String URL Filter.
1 function querySt(ji) { 2 hu = window.location.search.substring(1); 3 hu = hu.toLowerCase(); 4 gy = hu.split("&"); 5 6 for (i=0;i<gy.length;i++) { 7 ft = gy[i].split("="); 8 9 if (ft[0] == ji) { 10 return ft[1]; 11 } 12 13 } 14 15 return ""; 16 }
Usage:
- Parameter: String – in lowercase (to avoid any confusion or mismatches)
- querySt(“string”);
For Example:
URL: http://servername/pages/test.aspx?ProjectID=PRJ0001
To retrieve the ProjectID value call the function as follows:
- querySt(“projectid”);
Prefill a list form field – External Data
You may remember that the SharePoint Designer Team Blog in June 2007 wrote about how to manipulate List Form Fields in MOSS 2007 and WSS 3.0. (Original Post)
In many of my projects we have to manipulate the list form fields on the newform.aspx and the editform.aspx for a variety of reasons, including:
- Data Integrity
- User Experience
- This post and many others in this series will go through how to pre-fill the various field types.
First off I shall start with what used to be one of the more advanced features in MOSS 2007 Enterprise but is now available as part of Business Connectivity Services in SharePoint Foundation and SharePoint Server 2010.
The External Data Field (formally the Business Data Field)
The standard way to pre-fill a BDC value in SharePoint 2007 was using the function below and this hasn’t changed in SharePoint 2010.
1 function getBDCTagFromIdentifierAndTitle(tagName, title, count) { 2 3 var tags = document.getElementsByTagName(tagName); 4 var myCount = 0; 5 6 for (var i=0; i < tags.length; i++) 7 { 8 var tempString = tags[i].id; 9 10 if (tags[i].title == title) 11 { 12 myCount++; 13 14 if(count == myCount) 15 { 16 return tags[i]; 17 } 18 } 19 } 20 21 return null; 22 23 }
However, what has changed in SharePoint 2010 is the title part of the function call.
1 function setBDCValue(prefillValue, bdcItemNumber) { 2 getBDCTagFromIdentifierAndTitle("TEXTAREA","External Item Picker", bdcItemNumber).value = prefillValue;//value; 3 getBDCTagFromIdentifierAndTitle("DIV","External Item Picker", bdcItemNumber).innerText = prefillValue;//value; 4 getBDCTagFromIdentifierAndTitle("A","Check if External Item exists", bdcItemNumber).onclick(); 5 }
The only change between 2007 and 2010 is the title section of each element within the External Data picker control.
- TEXTAREA title: “External Item Picker”
- DIV title: “External Item Picker”
- A title: “Check if External Item exists”
Usage:
You need to ensure that the functions “setBDCValue” & “getBDCTagFromIdentifierAndTitle” are available on the newform.aspx and / or the editform.aspx (please see future post regarding this).
You also need to gather the value you are trying to prefill. This could be via the query string or some other method.
Once you have everything in place, the function call is as follows:
setBDCValue(prefillValue, bdcItemNumber)
- prefillValue = String value to prefill the control
- bdcItemNumber = the External Picker location on the page.
I.E. if there are three External Data controls, inserting you prefill value into the 2nd control would be as follows:
- setBDCValue(“Hello World”, 2);
You can use the function multiple times on the page if you need to prefill more than one control.
I hope all that makes sense, expect similar tutorials for the rest of the field types over the coming days / weeks.






You must be logged in to post a comment.