Wednesday, 29 February 2012

SharePoint No-Coding: Parameter Check

This is the third post from ‘No-Coding Solutions’ series. The first post showed you open any InfoPath form on a custom SharePoint web part page. The second one was on how to customize display values for a form. In this one will show you how to implement simple parameter check on your site pages. Well, this is not exactly no-coding, since the check itself is done with jQuery script, but still the approach is pretty straight-forward and does not require deployment, solutions creation etc. – just a JS file that is included to the pages.

On some of the site pages I have a data form web parts which display details of an item. To get the proper item, its ID is passed as URL parameter. If the parameter is missing details cannot be displayed and this makes the page look inconsistent. This is why I have created a very simple script file to include to my site pages that performs the check and if the parameter is missing to redirect user to another page.
The script looks like this:
There are many samples for URL parameter scripts on the Internet. This is the one I used for my sample. As you can see there is a check if ‘id’ parameter is on the page and if not user is redirected to ‘ParamError.aspx’ page. This page has nothing more, but a text saying that required parameter is missing.
The script is saved in simple text file, and included to site assets. Then, on the pages where this check should be performed, I have added a content editor web part and set its source to be the text file with content check.

No comments:

Post a Comment