Sunday, October 18, 2009

(Looping) Timer Workflows Using SharePoint

Timer Workflows

It is often a requirement of a Workflow in SharePoint to monitor and respond to various dates such as a start or due date.

If the timer is not the main function of a Workflow, it can be created as a separate Workflow to that both can run in parallel with full functionality.

Looping Timer Workflows

To have a looping timer workflow (eg. send a daily notification/reminder until a specific condition is met), the workflow must start when an item in the list is changed, and when it is created depending on the scenario.

At the start of the workflow, test if the required condition has been met, and stop the workflow if it has. If the condition has not yet been satisfied, the workflow can continue.

As the workflow will initiate after an item is modified, it is possible for multiple instances of the same workflow to be initiated. To prevent this, a custom (boolean) field is added to the list which is used to determine if an instance of the workflow is already running. When the workflow starts, it first tests if the value of a custom field (eg. "timer_waiting") in the current item is set to true/yes. If true, another instance of the workflow is already running and the current can be stopped. If false, the custom"timer_waiting" field can be set to true/yes to stop new instances from starting until the current is complete.

If the workflow is to continue, perform the required date calculations (current date + 1 day), store in a workflow variable, then wait until the date determined. Send the email, or perform other actions after the workflow has finished waiting (next workflow step).

To complete the workflow, set the field in the current item "timer_waiting" back to false/no to allow a new instance of the timer workflow to start.

If the SharePoint (MOSS 2007) Server has no service packs installed or Service Pack 1 only, updating the field in the current item workflow will cause another instance of the workflow to start, creating the looping functionality. If service pack is installed, a separate list must be used to trigger the first again to enable looping workflows.

For more information about looping workflows in general, as well as the changes to looping workflows made when Service Pack 2 is installed, see Service Pack 2 prevents an on-change workflow from starting itself.

InfoPath Error - Updating Content Type Failed When Publishing to SharePoint

When Publishing an InfoPath Form to a SharePoint site Content Type, the process may fail when trying to Update the Site Content Type if there are a large number of fields being promoted to SharePoint columns/fields in the Content Type with an "Updating Site content Type Failed" message.

One solution for this is to create a separate list with a lookup column/field back to the list which uses the Content Type created by InfoPath. The fields which are removed from the Content Type can be added to the separate list instead.

When the InfoPath Form is submitted, rules can be configured to create or update an item in the separate list which corresponds to the form being submitted, with the additional data.

How to Solve:

1. Make a full backup the InfoPath Form Template and the SharePoint Site (Content Types, Lists, etc.)

2. Choose which fields to add to the separate list instead of promoting/submitting with the form data.

3. Remove the fields from the list of promoted fields (Tools -> Form Options -> Property Promotion - or remove the fields when you next publish the form)

Note: Enough fields need to be removed to allow the form to be published successfully, as well as consistently. At this point, if you can't get the form to publish to a Content Type without receiving an "Error updating Content Type" (or similar) message by reducing the number of promoted fields, then the problem is caused elsewhere and the solution in this article will not apply.

4. Add a CAML XML template Data Connection to store the data required to add or update an item in the separate list. See InfoPath - Update Existing SharePoint List Item Programmatically Using CAML for details.

5. Add event handlers or and a main function to populate the CAML template with the data required to create or update an item in the separate list. See InfoPath - Update Repeating Elements/Nodes in a Secondary Data Source for details.

6. Create a Submit Data Connection which uses the UpdateListItems Web Service and the CAML template (created in Step 4) to create or update an item in the separate list. See InfoPath - Update Existing SharePoint List Item Programmatically Using CAML for details.

7. Configure rules to submit the CAML template using the Data Connection created in Step 6, then submit the form using the main submit data connection when the form is submitted. See InfoPath - Update Existing SharePoint List Item Programmatically Using CAML for details.

Thursday, October 15, 2009

InfoPath Tip - Show text field if user selects other

InfoPath Basics - Display text box if user selects Other using conditional formatting

Promote two fields to a single SharePoint or Database column/field.

This article demonstrates how to configure an InfoPath form to display an optional text box for the user to enter a custom value if not available from the list of options. A separate field in the main data source of the InfoPath form will be used to store the value of the selected option, or the custom value if supplied by the user. Rules are set up to set the value of the separate field in the data source when an option is selected or when a custom value is entered into the text box.
When submitting the form, the text field with either the value selected, or the optional text input entered if the user selects other can be promoted to a single SharePoint column, or database table instead of promoting both the option field and the text field containing the "Other" value if selected.

Conditional formatting is also used to hide the text box until the user selects "Other" from the list of options.


Process:

Set up the Initial InfoPath Form

1. Design a new form template using InfoPath 2003 or 2007

2. From the Task Pane (CTRL+F1), open the Controls toolbar

3. Double click, or drag an Option Button control onto the default view of the form template. Enter the number of options required (remember to add an additional option for "Other").









Note: In this example, the Option Button will have 5 options including "Other".
The name of this field in the Main Data Source will be "Options"

4. Right Click the first Option and select "Option Button Properties..."



















5. Enter a Field Name for the field. Note: You only need to set the field name on one of the options for it to be applied to all.

6. Enter the value which will be used when this option is selected for the "Value when selected".

7. Press Ok

















8. Repeat Step 6 for each option. Enter "Other" as the value when selected for the final option.

9. Add a text field control to the form template (main data source) for a user to enter a custom value if required.








Note: In this example this field will be called "Other".

10. Add a separate text field to the form's Data Source only to store the selected value, or the value from the "Other" field by selecting "Add..." from the menu after right clicking the "myFields" group.













Note: For the purpose of this article, this field will be called "OptionSelected". This field does not need to be added to the form template. This field will contain the selected value from either the "Options" field or the custom value from the "Other" text field if required, and is explained further in the article.


Add Conditional Formatting to hide the "Other" text field when it is not required

11. Right Click on the "Other" text field control on the form template.
12. Select Conditional Formatting...
13. Press the "Add..." button to add a condition
14. Select the "Options" field created in step 3, "is not equal to" for the condition, and a text value of "Other" to test against (Select "Type text..." from the options).





15. Tick the "Hide this control" option for the formatting to be applied.









The "Other" text field will now only be visible when the user selects the "Other" option radio button.


Create Rules to set the value of the separate text field to be submitted with the form

15. Right click on any of the Radio Button options and select "Rules..."

16. Click "Add.." to create a new rule for this field.

17. Set the condition to the "Options" field, "is not equal to", Type "Other" as the value to test against.

18. Click the "Add Action..." button.

19. Select "Set a field's value" from the list of Actions

20. Select the "OptionSelected" field from the Main Data Source for the "Field" option

21. Select the "Options" field for the "Value" option.














This rule will now set the OptionSelected field to the value selected by the user if "Other" was not selected.

22. Right Click on the "Other" text field and select "Rules...", Click "Add..." to create a new rule for this field.

23. Set the condition for the rule to the "Options" field, "is equal to", and "Other" for the value.

24. Click the "Add Action..." button.

25. Set the Action to "Set field's value"

26. Set the "Field" option to the "OptionSelected" field

27. Set the "Value" option to the "Other" text field (current).














28. Right click on the OptionSelected field in the Main Data Source and set the default value to the default value of the "Options" field.















This will ensure that the OptionSelected field will always have a value in the case that a user submits the form using all default field values (rules would not have been applied as no changes we made to fields in the form's Data Source). If using the Options field as the default value as apposed to typing a specific default value, you will need to un-check the "Update this value when the result of the formula is recalculated" option to prevent the OptionSelected value being overwritten to equal the selected value of the Options field when an option is selected (rules are used to set the value of the OptionSelected field as explained above).

Conclusion

When a user selects one of the options available, but not the "Other" option, the value selected is set as the value for the separate text field created using rules. When the user selects "Other" from the options, the "Other" text field will become visible for the user to enter a custom value. When the user enters a custom value into the "Other" text box, rules are also used to set the selected value as the value for the separate text field in the main data source.

The separate field will always contain the value selected or manually entered by the user, which when promoted to a SharePoint or database column instead of promoting both the option button control and the "Other" text box. The separate field does not need to be added to the form template, as the value of the field will be set using rules when a user changes a value when completing the form.

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: