Tuesday, September 22, 2009

XSLT String Manipulation - Remove spaces in Field Value for use in URL

XSLT function sets the value of a parameter to the value
of the required field, after processing to remove spaces.

The parameter is then used to set part of url in the href attribute of an <a> tag.



<xsl:template name="dvt_1.groupheader0">
<xsl:param name="fieldtitle" />
<xsl:param name="fieldname" />
<xsl:param name="fieldvalue" />
....... other template params

1. Add a parameter to store

<xsl:param name="stringNoSpaces" >
<xsl:call-template name="stringreplace">
<xsl:with-param name="stringvalue" select="@Field-XPath" />
<xsl:with-param name="from" select="string(' ')" />
</xsl:call-template>
</xsl:param>

....... main template code

<a href="/FirstURLComponent/{$stringNoSpaces}"><xsl:value-of select="$fieldvalue" /></a>

....... remaining template code

</xsl:template>


2. Add string replace template after the main template:

<xsl:template name="stringreplace">
<xsl:param name="stringvalue" />
<xsl:param name="from" />

<xsl:choose>
<xsl:when test="contains($stringvalue, $from)"><xsl:value-of select="substring-before($stringvalue, $from)" />
<xsl:if test="contains(substring($stringvalue, 1, string-length($stringvalue) - 1), $from)">
<xsl:call-template name="stringreplace">
<xsl:with-param name="stringvalue" select="substring-after($stringvalue, $from)" />
<xsl:with-param name="from" select="$from" />
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$stringvalue" /></xsl:otherwise>
</xsl:choose>
</xsl:template>





The value of the @Field-XPath field will processed by the string replace template to remove all spaces from the string.
The processed string is stored in the stringNoSpaces parameter to be used or displayed by the XSLT template
for a Data View Web Part.

Tuesday, September 15, 2009

Custom Publishing Page Layout using SharePoint Designer













Overview:
This article demonstrates how to create a customised Publishing Page Layout which can be used to add publishing pages to a SharePoint site with publishing features enabled. The page will be created from a content type which contains additional fields which are to be displayed on the publishing page both when it is being edited and once it has been published. This article also demonstrates how to display fields only when a publishing page is being edited using an Edit Mode Panel if required.








1. Activate Publishing Features on the SharePoint site:
2. Create Publishing Layout Content Type
3. Create Publishing Layout from the Content Type
4. Customise the Publishing Layout using SharePoint Designer
5. Add the Content type to the Pages library on the SharePoint site
6. Create a new Page from The Custom Publishing Layout

Requirements:
  • SharePoint (MOSS 2007)
  • SharePoint's Publishing Features
  • SharePoint Designer (2007)
SharePoint Designer is now available for Free. Download SharePoint Designer from the Microsoft Website.


1. Activate Publishing Features on the SharePoint site:
Publishing features need to be enabled on the SharePoint site which uses the features. To ensure that publishing features are enabled, you can either create the SharePoint Site from the News, or Publishing Site templates, which have publishing features enabled, or enable the Publishing Features on an existing site in the site collection.

Check the status or enable/disable the Publishing Features on a SharePoint site:
  1. Go to the Site Settings page of the SharePoint site
  2. Select Site Features, located under the "Site Administration" heading.
  3. Enable Publishing Features if required.






Enabling Publishing Features on a SharePoint Site will:
  • Create a Documents, Images and Pages library to be used when creating publishing pages on the site. The Documents and Images libraries are used to store files or images which are uploaded when creating content using a Publishing Page Layout. The upload dialog allows a user to easily select the Site Collection Images library, or the current (Publishing) site image library for an image to be uploaded for use in a Publishing Page Layout.
  • Add the "Create Page" and "View All Site Content" options to the "Site Actions" menu of the site.

2. Create Publishing Layout Content Type
When creating or customising a publishing layout which is in an article format which has common fields that the OOB "Article Page" content type such as start and end dates, article title, body, audience, etc., it may be quicker to create the custom Publishing Layout Content Type from the Article Page content type. If you require a custom set of fields on the publishing page, create the content type from the "Page" content type which is a core component of the publishing feature provided by SharePoint.

Process:
- Create the Initial Content Type
  • Browse to the Content Type Library at the Site Collection root, or the content Type Library of the site which will use the Publishing Features.
  • Site Settings -> Site Content Types (under Galleries heading)










  • Select "Create" to add a new Content Type.














  • Enter a name for the content type and description if required.
  • Select the "Article Page", or "Page" Publishing Content Types. If you are creating a news article like page layout, it may be more efficient to create a custom Article Page and modifying to suit rather than starting from scratch.








- Add Additional Columns/Fields to the Content Type if required
  1. Additional metadata fields can now be added to the Publishing Layout Content Type if required, by following the same procedure as you would to add a field to any Content Type in SharePoint.
  2. Open the Content Type if required by selecting it from the content type library
  3. Select "Add from Existing Site Columns" if the additional metadata fields/columns are already available on the current SharePoint site, or select "Add from New Site Column" to create a new column.
In this example I have created an additional column called "Audience", which is a choice field with two options; Internal and External (Below).


















3. Create Publishing Layout from the Content Type
Once the Publishing Layout content Type has been created, a Publishing Layout can be added to the Materpage library by selecting the custom content type created in Step 2 from the options available when creating a new Masterpage or Page Layout.

Process:
  • Browse to the Site Collection Masterpage Library, or the Masterpage Library on the site which the Publishing Layout Content Type was added to in Step 2 if not the Site Collection root.












  • Press the "New" button on the Masterpage Library.
  • Select the Publishing Layout Content Type created in Step 2 from the list of options.
  • Give the Publishing Layout a short, but descriptive title, as this will be used to destinguish the Publishing Layout from others when selecting from the available options.









  • Press Ok to create the Page Layout.

4. Customise the Publishing Layout using SharePoint Designer
Once the Publishing Layout has been created from the content type containing the custom fields, it can the be opened using SharePoint Designer and modified as required. Additional fields from the Publishing Layout Content Type can be added to the layout to be displayed when the page is checked in or published. If a metadata field is required for the Publishing Page Layout, but does not need to be visible on the page once it has been published, Edit Mode Panels can be used to display the containing fields only when the page is being edited.

Process:
  • Using SharePoint Designer, open the Publishing Layout from the Masterpage Library created in Step 3, or select "Edit Using SharePoint Designer" if available on the Edit Menu of the custom Publishing Layout.

















  • Apply the required layout and formatting to the publishing page by creating empty regions/cells where content fields will be placed.
  • Open the Toolbox - Task Panes -> Toolbox
  • From under the Page Fields and Content Fields Headings, drag the required fields into the empty regions on the publishing page.





















CSS Styles
You can set the styles for content field elements on a Publishing Page using the "Tag Properties" task pane. Set the CSS class of the element to a class which has been set up to format display the element as required (See Below).




















Edit Mode Panels
In a Publishing Page Layout, fields inside an Edit Mode Panel not be visible when the page is not being edited. This allows metadata fields which are required for each publishing page to be added to the layout, but not displayed in the publishing page once checked in, or published as a major version.

How to Add an Edit Mode Panel to a Page Layout:
  • Open the Toolbox - Task Panes -> Toolbox
  • Under the Server Controls heading of the Toolbox in SharePoint Designer, drag the "EditModePanel" control into the required region of the publishing page.


















  • If using the code view only, the EditModePanel control can be added to the page by dragging the control into the required section of code, or by right clicking the control in the toolbox and selecting "Insert".
  • Add publishing layout field elements to the Edit Mode Panel by dragging the required content field into the Edit Mode Panel.
  • If using the code view only, add the content field tag to the Edit Mode Panel tag (See Below)













5. Add the Content type to the Pages library on the SharePoint site
Add to the list of available Page Layouts when creating a new page from a Publishing Page Layout, to include the custom Publishing Page in the list of options.
  • Browse to the Pages library of the SharePoint Publishing Site













  • Open the settings page for the Pages Library
Settings -> Document Library Settings









  • Select "Add from existing site content types".
  • Choose the Publishing Layout Content Type created in Step 2





  • Press Ok.

6. Create a new Page from The Custom Publishing Layout
A new page can now be created from the custom Publishing Page Layout by pressing the new button on the Pages library. Give the page a name and description, then select the Page Layout from the list of options and press the "Create" button to create the page.
















Once the page is Checked in or Published after it has been edited, it can be viewed in a browser by opting the address/URL to the page in the browser, or by selecting the page from the Pages Library of the publishing site.

Friday, September 11, 2009

Solved: Can't Group By Choice Column in SharePoint List View

By Default, items in a SharePoint list can't be grouped by a Choice field if it allows multiple selections (checkbox).

To be able to group by the value of a Choice field in a SharePoint list or library which allows multiple selections, you need to ensure that the Choice field/column is set as Radio Buttons or a Drop Down Menu. Both of these options only allow a single selection of the available choices, which is required to allow grouping by the column/field using Standard SharePoint List views.

To group by a Choice field which allows multiple selections (checkboxes), convert the Web Part to a Data View using SharePoint Designer, then apply grouping doing the following:

1. From the "Common Data View Tasks" menu for the Data View Web Part, select "Sort and Group:" from the options to open the Sort and Group Dialog, add any field into the Sort Order section to activate the "Edit Sort Expression..." button. Click the "Edit Sort Expression..." button to open the Advanced Sort Dialog.

2. From the list of fields, add the Choice field, and make sure that the field reference is the only value in the "Edit the XPath expression" input.
The field reference should begin with an @ symbol followed by the internal name
of the SharePoint column/field (example: @Location). The value from the
selected column will display in the Preview box if items in the list/library
match the specified criteria, which in this case is a simple column/field value
(no conditions or calculations required).

3. Press OK on to close the Advanced Sort Dialog. Select the Choice Field from the list of fields in the "Sort Order:" box, then select "Show Group Header" under Group Properties. This will result in items being grouped by the value in the choice field which allows multiple selections.

Wednesday, September 9, 2009

InfoPath Form Content Type & Template Version management

How to manage updated versions of InfoPath form templates when used as Site Content Type.

The following article demonstrates how to ensure that an InfoPath form created from an older version of the form template continue to load from the template version which they were created from, while any new form submitted to the library will always use the latest version of the form template. This may be required when InfoPath forms are being integrated with SharePoint workflow, as the workflow will be set up to function using data from fields in the most recent version of the form template. If the main data source in the InfoPath form template is updated, the SharePoint Workflow may also need to be updated to cater for any field changes, or additional fields which are required by the workflow. Once the Workflow has been updated to work with the most recent form template version, any new forms submitted to the library will open from the new template, which will then start the updated version of the Workflow. Previous forms created from an older template versions will continue to load using the same template version in which the form was created. Any running Workflows will also continue use the workflow version which was current at the time the form was initially submitted.

Submitted forms can be "Relinked" to the current version of the template as long as they are stored in a SharePoint Form Library. If the forms are being submitted to a standard document library, the "Relink Documents" View and functionality will not be available. There are risks involved when relinking forms to the a more recent version, as modifications to the Form's Data Sources or code may result in the xml file created from an older not being able to open if data can't be mapped to fields in the main Data Source.

Be sure to test relinking an older form to the most recent version, by making sure that the form can open, that calculations, validation, rules and code are working as expected and that the form can be submitted successfully.

If you are certain that a form which is linked to an out-dated InfoPath Form template will function properly once "Re-Linked" to the current version, existing forms can be re-linked using the "Relink Documents" view of the SharePoint Form Library containing the submitted forms.

The process for creating, updating and managing incrementing InfoPath Form Template versions in a live environment, while ensuring that functionality in previous versions of the forms template remains is as follows:

1. Create a SharePoint Document library to store InfoPath form templates.
This library will not be used to submit completed forms to. The sole purpose of this document library is to store template versions.
- Set permissions on the document library to grant Read-Only access any user who requires access to the form.

2. Create a SharePoint Form Library for completed forms to be submitted to.
- See Submit InfoPath form to SharePoint List or Library using Content Type for details and instructions on how to set up InfoPath Forms to submit to a SharePoint Library by publishing the form as a site Content Type. This relates to steps 2, 3, 4 and 5.

3. Configure the InfoPath Form Data Connection to submit to the Form Library created in Step 2.
See reference in Step 2 above for instructions.

4. Publish the Form Template as a Site Content Type.
This will be used as the default Content Type for the Form Library the submitted forms will be stored in. The form template will be published/saved to the Document Library created in Step 1 during the Publish process.

5. Set the Content Type created in Step 4 as the default Content Type for the Form Library that completed forms are submitted to (Created in Step 2). See reference in Step 2 above for instructions.


Making Changes/Updates to the InfoPath Form Template once it is already in use.
Once you have all required components created and configured in the above steps, you will be able to make changes to Form Template without effecting previously submitted forms. This is possible as the Form's Content Type has been set as the default for the Form Library containing the forms.

When a user presses the "New" button on the Form Library, the a blank form will load from the most recent version of the form template. Once the form has been submitted, the template which it was created from is added to the forms XML so that it knows exactly which template to load when opening the form. If an update is then made to the Form Template, the submitted form will continue to load from the form template which it was created from unless "Relinked" to the current version.

The key is not to overwrite a previous Form Template with an updated version, but instead use a manual versioning system by adding the version number to the template filename when publishing the updated template. After the form is saved with a new filename, the Content Type is automatically updated to load new forms from the Updated version. As the previous versions of the template still exist in the form template document library, forms which were created from these versions will continue to open properly.

When making changes to an InfoPath Form template stored on a SharePoint site, you will be required to save a copy of the template somewhere else to be edited. An easy way to check if updates made to a form template will break previous forms if the current version is overwritten with the updated version, is by the message display by InfoPath when saving the form. If changes have been made to the Main Data source, a warning will be displayed when the form template is being overwritten if InfoPath detects that Updates make the different versions incompatible with each other. If this message is displayed, it is usually a good idea to save the Update form template with a new filename to ensure the older version is still accessible to forms which were created from it.


Related Articles: