Showing posts with label Tips and Tricks. Show all posts
Showing posts with label Tips and Tricks. Show all posts

Monday, March 21, 2011

How To Add column to all content types and lists in SharePoint

Adding a column to all content types and list in SharePoint is simple, but there are implications that first need to be considered before doing so.  Once completed, the new column will be available in all existing content types in the Site Collection, as well as lists and libraries that exist on SharePoint sites.


Implication:
The implication of this change, is that the process to reverse is not nearly as simple as the process to implement. Removing the column from the content type(s) will not remove the association of the column with lists that previously had the global column.  A custom solution could be developed to automate removal of the column from content types and lists, but the alternative would be to manually remove each instance which could be time consuming in larger, more complex environments.


Process:
Content Types in SharePoint inherit from the Item content type.  If a column is added to this content type (with the “Update all content types inheriting from this type?” option selected), the column will also be added to all existing content types in the site collection.

  1. Navigate to the Content Type Gallery at the root of the site collection, via the site settings page
  2. From under the List Content Types heading, select the “Item” content type.
  3. Press the “Add from new site column”, link to add a new global column, or the add from existing option to add an existing column to all content types.
  4. (If adding a new column) Complete the information about the new column, ensure that the “Update all content types inheriting from this type?” option is selected, and press OK to add the column.

Saturday, March 19, 2011

Dynamic List Filter Menu Using Data View Grouping

This article explains how to create a dynamic filter menu for content in SharePoint.  Methods from the article SharePoint: List Distinct (unique) values from a specific column in a list are used to obtain unique values from a specific column in a SharePoint list to be displayed as each menu item.  When an filter option from the menu is selected, content on the page will be filtered based on the selection.  

For a single menu displaying filter options dynamically, you only need to associate the menu with one column from the main list.  When an option is selected, the browser is redirected to the same page with a query string parameter set to the selected filter parameter using JavaScript.  The main list on the page is then configured to filter contents based on the parameter.

Components:
  • Document Library with custom column "Heading"
  • One Web Part page with the following components:
    • Data View Web Part displaying the actual documents in the library
    • Data View web Part displaying the possible filter options (from the Heading column)


Usage:
  • When a filter option is selected from the menu Data View, the browser will be sent to the current page with the selected option included as a Query String Parameter (using link or JS).
  • The main Data View web part would be configured with a custom parameter obtained from the Query String.  The custom parameter would be used as filter criteria for the Data View.  The result is that when an option from the dynamic menu is selected, the documents listed in the main Data View will be dynamically filtered based on the selected option.


JavaScript Reference:
The “How To” instructions below refer to JavaScript functions used for Query String Manipulation. To view details about the functions referred to below, as well as other functions for hyperlink/query string manipulation, see:

Query String Manipulation using JavaScript
    - Add Query String Parameter using JavaScript - addParameter()

How To:
  1. Create a new Document Library, or use and existing one if required.
  2. Add a custom column to the library (or content type if using custom content types).  In this example the column will have the title “Heading”, and will be used to list menu options, but it can have any title as required.
  3. From the view menu of the document library or the setting page, select the “Create view” option to add a new view.
  4. When viewing the newly created View page, select the “Edit in SharePoint Designer” from the file menu, or manually open the site and page for editing in SharePoint Designer.
  5. Add a second instance of the same Document Library Web Part to the page above the existing.  Set the crome state to None in the Appearance section if required.
  6. Right click on the new Web Part and select Convert to Data View option.
  7. Once a Data View Web Part, open the Sort and Group dialog, and add criteria to group the list by the “Heading” column.
  8. In the design pane of the page, right click on one of the listed items (documents) and remove the row from the table.  This will remove all list items resulting in only the groups remaining.  Remove additional functionality from the groups, such as the expand, contract button/link or css styles.
  9. Format the group value as a hyperlink, with “#” as the value for the href attribute.
  10. Add an “onclick” attribute, with a call to the addParameter() JavaScript function.  The value of the selected filter option and the parameter name is passed to the JavaScript function which adds the parameter to the current url using a redirect.


If there are no existing parameters on the current page url, the easiest method to configure a hyperlink to add a Query String Parameter to the current page is to set the href attribute to the following:

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

Using the above (simple) method will replace any existing parameters in the current url with the new parameter and value.  For a single dimensional menu, using this method to add Query String parameter and value to use as filter criteria on other Web Part s on the page would be fine.  For multi dimensional menus (main and sub menu), you may need to retain the parameter in the Query String that determines which main/primary heading when adding the sub-heading filter parameter.  In this case, JavaScript can be used to add the new parameter to the existing Query String.  Using JavaScript to manipulate the query string is a better method to use in either case as existing parameters will always be retain, but would obviously require that JavaScript be enabled on client browsers.  




More Resources for SharePoint Development & Customisation:
 

Monday, March 14, 2011

SharePoint: List Distinct (unique) values from a specific column in a list

The following describes two methods to list distinct/unique values from a specific column in a SharePoint list.  An example where this may be useful is a menu system providing filter options for items in a list, using only values that are being used at the time.  


Display Unique Values using Data View Grouping (No Code):
Obtaining a distinct/unique list of values from a specific column in a SharePoint list can be achieved easily using a Data View Web Part, and by applying sort and group criteria to group items.  When grouping (group by) criteria of a Data View web part has been provided, the result is a distinct (unique) list of values from the particular column in the list that will be displayed as group headings.  Once the Data View is listing items grouped by the specified column, you can manually modify (remove cells/rows) the XSL template used to display the table to remove the actual list items from under each group (use Design mode in SPD to easily manipulate the default table layout).

The resulting Data View will list the group names (no items listed), which will be each unique value found in the specified column across all list items in the list.  Using the grouping functionality will ensure that only unique values are returned, as long as you sort by the same field to ensure that items are grouped correctly.  Once you have the list of group headings you can then modify the values displayed to be formatted as hyperlink or another control.  I typically use hyperlinks or buttons with calls to JavaScript functions that add Query String parameters to the current url.
 

Display Unique Values using XSL:
Selecting a list of unique values in a column that contains multiple instances of the same value can also be achieved using an XSL template and the “following” operator.  The following was achieved with the help of this article: http://www.bernzilla.com/item.php?id=333 , and displays a unique list of values from the Title column of items in the list.  


   <xsl:template match="/" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:asp="http://schemas.microsoft.com/ASPNET/20">
       <xsl:variable name="unique-list" select="/dsQueryResponse/Rows/Row[not(@Title=following::Row/@Title)]" />
       <xsl:for-each select="$unique-list">
       <xsl:value-of select="@Title" />
       </xsl:for-each>        
   </xsl:template>
</xsl:stylesheet>


Implementation Examples:
There are numerous circumstances where you need a distinct list of values from a specific column in a list, across all items.  A common scenario may be a dynamic menu system, that provides filter options for content on a page based on existing values in a particular column.

Implementing a dynamic menu system using this technique would involve selecting one or more columns from the main list in SharePoint to be used when listing filter options dynamically.  The menu should list all unique values from a specific field in the list, and be formatted in a way that allows the page to respond to a selection by filtering content.  


The simplest form of this would be a dynamic filter menu displaying options from one field in a list.  When an option is selected, the content on the page (from the associated list) is filtered based on the selected option.  Creating a multi-dimension menu to filter using multiple columns  is also achievable using this technique, where a sub-menu would also exist on the page.  In this case, when an option is selected from the main menu, the sub-menu options are changed (filtered) to show options relevant to the main menu selection.  Once an option is then selected from the sub-menu, the list or library on the page is then filtered using both fields.


More SharePoint Designer Training & Tutorials at SPDTraining.com

Sunday, September 19, 2010

Multiple Site Permissions Report Using Excel

Managing SharePoint site permissions can become difficult when the Site Collection expands to have many sites with different permission settings for each. This is especially true if the permissions are not inherited from a parent site, list or library, or item level permissions are used on items in a list or library.

Some third party reporting tools provide an overview of the permission applied across a site collection, with the possibility to drill down to more detailed information about the configuration of groups and permissions applied to each site. This article explains how to use Excel to create a single report with  permissions of multiple sites in one site collection.


This is achieved by using data connections and a "Web Query", by selecting the "world" option in Excel 2007 to create a data connection to configure. The address on the site permissions page for each site is added to a separate Web Query link, which retrieves the specified page from SharePoint, it retrieves data from these regions on the page when configuring the data connection. If the table that all users / groups and their assigned permission levels is selected as the region to use, the spreadsheet can retrieve this data from SharePoint and display on the Excel sheet.

Once a connection is configured for each of the sites, the spreadsheet will list permissions from each of the sites as dynamic data sources / connections are renewed. You may need to configure a data connection to insert additional rows if there is not enough space in the current spreadsheet to fit the updated information. Configuring data connections on a periodic background refresh time frame, or to download the data when the spreadsheet loads will help to ensure that the report will remain up-refresh to implement to date.

The report can be useful tool for SharePoint Administration, as it allows for permissions from multiple sites to be listed on an Excel spreadsheet, making it easy to see how the environment is configured. In some cases, specific permissions are required to view permission levels on a site or list so the user that the report must have access permissions for each of the sites included in the report.

Procedure:
  1. Note the urls of the Permissions page on any site you want to display data in the report
  2. Using Excel, select the "world" option from the Data Connections tab.
  3. Enter the URL of the page permissions for one of the locations in the "Address" field
  4. Select the region of the page you would like to draw data from
  5. Press "Import" to import data. You asked where the location data
  6. In the data connection properties, select "Refresh data when opening the file" if you want the data to be updated whenever the spreadsheet report opens.
  7. On the "External Data Range Properties" dialog (right click on the data, or select the"Properties"option on the Connections tab), select the option to insert new rows for data to make ensure that data from the different connections doesn’t overlap.
A further improvement could be to dynamically configure data connections from a list of sites found either directly from the SQL database, or by scraping the list of sites on the "site hierarchy" page on the site collection root. This can obviously lead to a very large number of connections needed to generate a report with permissions of all sites, so an interim step should be possible to include data from a small selection of the sites each time. Since the permissions page for each SharePoint site has the same layout, a macro or similar should be written to run the Web Query using the dynamic list of URLs, and by automatically providing the region the page that contains the information required.


More about SharePoint Permissions:

Managing content using permissions - Show or hide ASP / SharePoint controls or HTML using OOB functionality provided by the SPSecurityTrimmedControl class, which can be included in a .aspx Page or Master page using SharePoint Designer or Visual Studio. SharePoint: Show or Hide Content based on Permissions provides further examples of using SPSecurityTrimmedControl to restrict content to users based on their permission on the current site, list or item.

A list of Programmatic uses of the SPBasePermissions Enumeration, which is used by many components of the SharePoint Object Model. SPBasePermissions can also be used without requiring code with SPSecurityTrimmedControlas in the reference above.

Another  SharePoint Reporting tip:

SharePoint Designer allows you to run a range of different reports on a site and content in a SharePoint environment.  Using a Macro that is run in SharePoint Designer, it is possible to automate the process of running reports across multiple sites.  The article SharePoint Designer (2007) - Run reports for all sites programmatically explains how to do this, and includes the macro code to run the process.  All you need to do is supply you list of sites to run the reports on, select the type of report to run and the save location for the files generated for teh reports and off you go...


Thursday, August 19, 2010

Set SharePoint List Form Web Part field values using JavaScript when Creating New Item

How to set values of form fields generated by the SharePoint List Form Web Part when adding a new item to the list using JavaScript.

Using a custom metadata field in a SharePoint list to set categorisation & filter criteria that is later used by List and Data View Web Parts to arrange & filter content for specific audiences.  Depending on the audience that a user is in, I wish to set alternate default values for specific fields rendered by the List Form Web Part.

In most cases, a custom multiple choice field in the list will be set to a value which corresponds to the current user’s audience, but will sometimes need to be manually adjusted.  To improve the experience for end users, the appropriate checkbox option from the multiple choice field that corresponds to the current user’s audience will be selected when the form loads, and the default value for the field un-checked if required.

The custom field is used in multiple content types across the primary site collection.  I found that when the field is included in a form rendered by the List View Web Part for a particular list, the HTML element name and id is not the equal to the same field rendered by a List Form Web Part on another list.  For this reason, I included the javascript on the NewForm.aspx page only on the list i wish to implement the feature using a Content Editor Web Part (CEWP).

A separate CEWP containing the JavaScript for each audience was added to the page under the List View Web Part, then targeted to the corresponding audience.

The JavaScript used to update the field values is quite simple.  As the field i wish to update is a multiple choice field (check boxes), I needed two lines of code in the script; the first unsellects the original default value for the field (set via the column settings), then selects the checkbox option that corresponds to the current user’s audience.  As all CEWPs are targeted to each audience, only one should display and execute the JavaScript for each user.  If a user is a member of more than one audience, the value set by the bottom most CEWP will be applied to the field rendered by the List Form Web Part.

Depending on the type of field being updated, you will need to update the JavaScript to set the field value with the appropriate data type and data.  The steps below apply to a multiple choice field displayed as check boxes.

<script type="text/javascript" language="javascript" >
 <!--
      document.getElementById('checkbox default value id').checked = "";
     document.getElementById('checkbox required value id').checked = "checked";
  //-->
 </script>

1. To find the Id of the fields that are being updated, view the source of the NewForm.aspx page and search for the internal name for the field.  The field will be directly after a html comment containing information about the field:

<!--      

FieldName="fieldname"
FieldType="SPFieldMultiChoice"
-->

2. Once you have found the position in the source containing the form input you with to update, first copy the id of the checkbox field that is selected by default.

3. In the first line of the above JavaScript, replace the text 'checkbox default value id' with the required Id of the form element.

4. Repeat step 2 to obtain the Id of the check box option you wish to select.

5. Replace (in the second line of the JS) the text 'checkbox required value id' with the required Id.

When the page loads, the CEWP corresponding to the current user’s audience will be displayed, resulting in the JavaScript updating the field values/selections in the above form generated by the List Form Web Part.  The checkbox field specified in the second line of JavaScript will be selected, and the original default option unchecked.



Related: 

Wednesday, August 18, 2010

Useful Tip: Add a link to Create a New Document From a Content Type Template

I found a blog post by Andy Burns that explains how to find and use the javascript from the 'New' button on a Document Library with managed content types to add a link to any page which will open a new document from the template.

As the "add new document" link on the summary toolbar of a List or Data View Web Part links to the Upload page of the document library, i used the javascript from the new button instead to create a link that opens a new blank document from the content type template associated with the document library.  This meant that the default save location for the document was set to the document library.

Andy's post explains how to incorporate the javascript behind the 'New' button into a link on a different page.

The issue that I was attempting to resolve is that I wanted to use the link in client applications outisde of SharePoint.  this meant that I couldn't use javascript, as the function called was not available to the application.

My solution was to add the javascript to the head setion of a separate page to a function which is called by the settimeout() method after a few seconds.  Once the function is called and the blank document loaded, the script redirected to the default view of the document library.

I used the timeout method as the script was not working properly if the page had not fully loaded, as well as to display a brief message to the user informing them of the process before redirecting to the document library.  Redirecting to the document library also prevents an infinant loop if you press "Cancel" if asked to confirm opening the blank document, as the page is reloaded when the Cancel button is pressed.

Javascript:

function newDoc()
    {

        'create a new document from a specific content type template
        createNewDocumentWithProgID('http:\u002f\u002fserver\u002fsites\u002fSales\u002fDocuments\u002fForms\u002fSales Order Form\u002fnew.xlsx', '
http:\u002f\u002fserver\u002fsites\u002fSales\u002fDocuments\u002fForms\u002fSales Order Form', 'SharePoint.OpenDocuments', false);
        

        're-direct to the document library (default view)
        window.location = 'http://server/sites/Sales/Documents/';
    }
    setTimeout ( "newDoc();", 1000 );


View Andy's post: Add a ‘Create New Document’ link to a page

Sunday, January 24, 2010

SharePoint Designer: Get account details of the user who initiated the workflow using OOB Workflow Activities

Get account name of the user who initiated / triggered a workflow using OOB SharePoint Designer Activities:
The ability to access the account details of the user who started a workflow in Sharepoint is not supported when developing workflow using SharePoint designer and OOB workflow activities. The User data type allows selection of the User who created the item, but not the user who initiated the workflow. Using the Modified By field will return the user who made the most recent changes to the document/list item or meta data, but may not be the user who initiated the workflow. For example, if a workflow is used to set the approval status of a list item or document with content approval enabled is initiated, the user who published a major version of the documnent (submit for approval) will be the user who initiated the workflow regardless of who made the most recent changes to the document.

A number of solutions relating to this issue / limitation are available, including a workaround solution using OOB workflow activities and SharePoint designer explained below:

How to get the account name of the user who initiated a workflow using OOB workflow Activities and SharePoint designer:

1. Create/modify item in secondary list.
This action will be executed using the credentials of the user who initiated the current workflow. Once the list item from the secondary list has been created or updated, you can then retrieve the Creaded By or Modified By user.

2. Pause, then store the user who created/modified the secondary list item in a Workflow variable (string: "DOMAIN\user").
After the secondary list item has been created or modified, you can store the value of either the Created By or Modified By fields of the secondary item to get the account name of the user who initiated the current workflow. Note that you may need to configure the workflow to pause for 1 minute after creating or modifying the secondary list item, as it takes a few seconds for the account details to become available after creating or modifying the item.

3. Use the value of the workflow variable.
Once you have stored the user who started the workflow in the workflow variable, you can then use the value when setting the Assigned To, email recipient or any other field that uses the user account data type.


Related:

In sharepoint designer’s workflow editor how do I get the workflow initiators username?
"In Sharepoint designer's workflow editor I wish to retrieve the username/name of the work flow initiator (i.e. who kicked it off or triggered the workflow) - this is relatively easy to do using 3rd party products such as Nintex Workflow 2007 (where I would use something like {Common:Initiator}) - but I can't seem to find any way out of the box to do this using share point designer and MOSS 2007."

Wednesday, January 13, 2010

SharePoint Looping Workflow - How to: Loop through and process all items in a list

Objective
To use SharePoint workflows to loop through all items in a list to perform calculations, process and update metadata values, or concatenate the value of a specific column in all list items into a single string.

Background
The OOB workflow actions provided by SharePoint don't allow a loop to be configured explicitly. Instead, a number of workflows can work together to create a looping affect. Another limitation of Workflows in SharePoint using SharePoint Designer (SPD) is the inability to simply test if the user who initiated the workflow is a member of a SharePoint group, or to test if the value of a field in the item which initiated the workflow is equal to the value of a specific field from any item in a separate list.

For example, the OOB Approval Workflow requires that a user who is an Approver of changes to approve their own changes each time a modification is made. In many cases, Approvers are also the users who make many of the changes that require content approval which can result in the user wasting time and becoming frustrated when many documents/items need to be updated. To simplify the workflow, you could loop through each item in a separate list that lists each of the users who are approvers to check if the user who initiated the workflow is an Approver. If the user is an approver, the Content Approval Status of the item can be set to "Approved" making the changes visible to other users. The list of approvers would been to be stored in a list instead of a SharePoint group, as SharePoint Designer doesn't allow you to test if a user is a member of a group. Storing the list of approvers in a SharePoint list allows you, or someone else to easily add/remove users from the list. Note that the users added to the approvers list would still require the appropriate permissions applied to approve changes. To loop through the items in the Aprovers list, a looping workflow would need to be configured to process each item in the list.


How To Create a Looping Workflow in SharePoint

A number of lists will, along with multiple workflows configured to trigger each other will be used to create the looping workflow. As there is no option when developing OOB workflows using SPD to loop through items in a list, a separate workflow will be configured to perform the required actions on a single item. This workflow would start when an item is modified, completing the required actions/processing for the item. When complete, the "Item Processor" workflow will re-initiate the parent workflow which will then initiate a workflow to process the next item in the list. A custom Boolean (True / False) field "Processed", or similar will be added to the list that contains the items that need to be processed. This field will be used to find and trigger the workflows to process each item in the list once.

When all items in the list have been processed, the workflow not be able to find the next item in the list based on the specified criteria and as a result will cause the "List item not found" error and the workflow will stop.

As new instances of a workflow won't always start if there is another running instance that has an error, the parent workflow will be initiated each time by creating a new item in the Workflow Control list. The parent workflow can remove the workflow control item once it is complete to help keep the SharePoint lists tidy.


Considerations & Limitations
If Service Pack 2 or higher has been installed on the servers hosting SharePoint, workflows will function different to an environment at the SP1 level or less as after SP2, an "On Change" workflow won't re-initiate itself when the current item is modified. This can affect looping workflows, as they may have been configured to loop by updating the current item. The looping workflow solution detailed below should work on servers with or without SP2 installed.

Looping Workflow Components

Lists/Libraries:


Items - The list containing the items you wish to process using a loop.
The Items list will need to have a Boolean column/field added with a title "Processed" or similar, which will be used to create the looping functionality as well as to determine if an item in the Items list has been processed or not.

Workflow Control - The list to initiate and control the workflow loop. Use a custom list for the Workflow Control list, as the title of Workflow Control items will be used to help control the Parent workflow.

Workflows:

Item Processor:
- Associated with the list of items you wish to process.
- Starts when an existing item is modified.

Workflow Control:
- Associated with the Workflow Control list.
- Starts when a new item is created.


Looping Workflow Sequence:
Each step in the following sequence should be interpreted as a step in a Workflow created using SharePoint Designer. Step 2.2 (Items Processor) can be configured in as many workflow steps as required to complete the processing for an item. It is important that the remaining steps are configured and executed in the sequence below.

Workflow Control (Parent) Workflow (1):
1. Item created in "Workflow Control" list initiates parent workflow.
1.1 - Update the "Processed" field from an item in the "Items" list to No/false: find the item by searching for an item in the list where "Processed" = Yes/true
1.2 - Remove the current item as it is no longer required.

Items Processor Workflow (2):
2. Workflow starts when an Item is modified by Parent Workflow (Processed = No/false)
2.1 - Stop if "Processed" = yes/true (Prevent instances of the workflow running when they are not supposed to, if a user makes a change in the item which triggered the Item Processor workflow).
2.2 - Complete processing/actions required for the current item.
2.3 - Create a new item in the "Workflow Control" list to continue the workflow loop.
2.4 - Pause for 1 minute (allow the remaining items in the list to finish processing)
2.5 - Set Processed = Yes/True : Reset the item for next time it needs processing.

Looping workflow diagram (Click to enlarge):
Looping workflow diagram


















Looping Workflow Details:
1.1 The parent workflow starts when an item is added to the Workflow Control list. All the Workflow Control workflow needs to do then is update the value of the "Processed" field in of an item in the "Items" list, by finding the first item where "Processed" equals Yes/true. This will initiate the Items Processor workflow for first item found that matches the criteria. The current item in the Parent (Workflow Control) list can the be removed as it is no longer required.
1.2 - Once an Items Processor workflow has been initiated, the current item in the Workflow Control list is no longer required and can be removed. Once all items in the "Items" list have been processed, Step 1.1 of the Workflow Control workflow will have completed, as it will halt with the "List item not found" error, which will result in one (the last) item in the Workflow Control list to remain.

2.1 When the Items Processor workflow is initiated after a Parent workflow sets the "Processed" field to Yes/true, the first step is to test if the Processed field equals yes/true, and stop the workflow if it does not. This prevents the workflow from initiating out of the looping workflow context. If using SharePoint with SP1 or lower, the final step of the "Items Processor" workflow (Setting the "Processed" field back to Yes/true) can cause an endless loop. Stopping the workflow in the first step if Processed doesn't equal Yes/true will prevent an endless loop.

2.2 The next step(s) of the items Processor workflow complete the actions or processing required for the current item. This may include adding up the value of a numeric field to find the total for all items in the list, or concatenating the value of a field in from all items in the list into a single string which can then be used to perform more complex tests/tasks based on data from multiple items. If calculating or generating a single value or string from data from all items in the list, you will need to store the results of the calculations in a separate list item that each workflow would refer to and update after completing the processing for an item. For details of an implementation of this example, see the article How to wait for a change in any list, wait for multiple field changes in the current item (SharePoint Workflow) (Test if an item exists in a list with certain criteria, continue workflow if not and create a new item in the list with the specified criteria).

2.3 Creating a new item in the parent "Workflow Control" list re-initiates a new instance of the parent workflow, which will find and initiate the Items Processor workflow on the next item in the Items list that has not yet been processed.

2.4 Pausing for 1 minute allows the remaining items to be processed by the looping workflow sequence. After pausing for a minute, the "Processed" field in the current item is set to Yes/true to indicate that the item has been processed. This will also prevent further instances of the workflow initiating unless by another (new) instance of the entire looping workflow sequence.


Related Articles:
How to wait for a change in any list, wait for multiple field changes in the current item (SharePoint Workflow)
Test if an item exists in a list with certain criteria, continue workflow if not and create a new item in the list with the specified criteria

(Looping) Timer Workflows Using SharePoint
How to create a looping timer workflow (send a daily notification/reminder until a specific condition is met)


How to configure a workflow to start at specific time, then loop / repeat periodically (Daily, Weekly)The following method can be used to start a workflow at a specific time, then repeat periodically (each day). Periodic Workflow Processing: (send daily email notification or reminder)A useful implementation of this technique allows you to configure workflows to run as background tasks at a specific time instead of being triggered by a user manually, or after creating or modifying a list item.

SharePoint Workflow Errors: Descriptions, resolutions and WorkaroundsThe following table lists some of the common errors that can occur in a Workflow developed using SharePoint Designer. A short description of some of the likely causes for each error are also provided.

SPD Workflow - Test if value exists in any item in SharePoint list - create new item if not found
SharePoint Designer Workflow: How to test if a specific value exists in any item in a list without the workflow stopping due to a "List item not found" error if no items exist with the required value.

Monday, December 14, 2009

SharePoint Web.Config: How to Show Full Errors

Enable display of error details and stack trace when an error occurs

Replace the following error messages with a more meaningful description of the cause of the error by disabling custom errors and enabling the track trace to be displayed as well.

An unexpected error has occurred

An error occurred during the processing of...

To display full errors and the stack trace of the error, you need to modify the web.config file for the Web Application which SharePoint is running on. There are a number of web.config files required to configure various components of SharePoint. For help finding the correct web.config file, see Where is SharePoint web.config? See notes below for more information about modifying the web.config file to display errors.




Enable Custom Errors: Set the customErrors mode to "Off"


Find:

<system.web> ...

<customErrors mode="On" />

Change To:

<system.web> ...

<customErrors mode="Off" />



Enable the Call Stack Trace: Set the CallStack value of the SafeMode element to "true"

Find:

<SharePoint>

<SafeMode ... CallStack="false" ... >

</SharePoint>


Change To:

<SharePoint>

<SafeMode ... CallStack="true" ... >

</SharePoint>



Enable Debugging Mode: Set batch and debug to "true"

Find: <compilation batch="false" debug="false">
Change To: <compilation batch="true" debug="true">


Enable the ASP.NET tracing feature:
Include the following line in the <system.web> element of the web.config file.

<system.web> ...

<trace enabled="true" pageOutput="true"/>



By default, SharePoint will only display a basic message to users when an error occurs. The message is virtually useless when trying to troubleshoot an issue, so by enabling more descriptive errors to display, including the stack trace which should help you find the cause of the error. You should not make changes to the web.config file in a production environment, or while in production. Back up your entire SharePoint environment, including all databases prior to commencing any major troubleshooting. You should attempt to replicate and resolve the problem in a non-production environment, and apply the necessary changes to the live environment when it is not in production. In many cases, the web.config will not need to be modified in the live environment as the cause of an error will be known after troubleshooting in a production environment.

For more information about the web.config file, where to find it and which one needs to be modified, see
Where is SharePoint web.config?


Related:

Saturday, November 28, 2009

How to wait for a change in any list, wait for multiple field changes in the current item (SharePoint Workflow)

This article describes techniques which can be used when developing workflows in SharePoint using SharePoint Designer. They allow a workflow to wait for a field change in an item in another list, or to wait for multiple field changes in the current item before continuing.

This can be achieved by configuring an On Change workflow to stop if the required criteria is not met, instead of using "Wait for field Change in the current item" actions in a Parallel fashion which limits functionality. The first step in the workflow can contain as many conditions as required, using the standard tests against fields in the current item, or a field in an item in another list on the sameSharePoint site. If the conditions are not yet met, the workflow will stop. A new instance of the workflow will initiate every time data in an item is added/updated, and will continue only when all of the required criteria is satisfied. The action for all conditions in the first step will be to stop theworkflow and log a message.

Requirements


Create the workflow using SHarePoint Designer


  1. Load the SharePoint site using SharePoint Designer (File -> Open Site...)
  2. From the File Menu, select New to open the "New" dialog.
  3. From the SharePoint Content tab, select Workflow and then Blank Workflow
  4. Press ok to create the workflow.
  5. Set the name of the workflow
  6. Select the option to start the workflow when a new item is created, and when an existing item is modified. Un-check the option start the workflow manually if required. (On Change, On Create)

In the first step of the workflow, create a separate condition/action branch for each of the tests which need to be completed before the workflow can continue. For example, if you need the workflow to wait for a task in a separate list, but associated with the current item to be completed, you would create a condition which tests if the Task Status field of the task item is marked as "Completed". If not, the action will be to stop theworkflow . If you need to wait for multiple fields in the current item to change before continuing, a separate condition/action branch should be created for each, or at least a separate condition. Simple tests on yes/no fields can usually be added to the same branch without loosing functionality. Using a single branch with multiple conditions will also improve performance of theworkflow if there are a large number of conditions being checked each time the workflow starts.

When the conditions in the first step of the workflow are satisfied, the workflow can continue to the next step. In Step 2 of the workflow, a [workflow_started] field is set in the current item to indicate that an instance of the workflow is running. Any new instances will not run, as the [workflow_started] field in used as one of the conditions in Step 1 to determine if the workflow can start. Only one of instance of the workflow should progress to step to and beyond.


Example:

Workflow Step 1


Condition
  • If [Task Status] (separate list) does not contain "Complete"
Action
  • Stop workflow, log: "Task X not yet complete"




Condition
  • If [Project Code] (current list) "is blank"
  • OR: [Assigned To] (current list) "is blank"
  • OR: [workflow_started] (current list) equals "yes"
Action
  • Stop workflow, log: "Project details required"


Workflow Step 2


Step 2 and onwards will only run if all conditions were met in the first step. The first action which should be performed in Step 2 will be to set a [workflow_started] field in the current item to "yes" which indicates that an instance of the workflow is running. As only one instance of the workflow should run, the [workflow_started] field is used as a condition which will stop new instances from continuing past Step 1. The final step in the workflow will be to set the [workflow_started] field back to "no", or a separate [workflow_complete] field to "yes". If using a [workflow_complete] field, you may need to include a condition in step one of the workflow to prevent new instances of the workflow starting if one is running, or is already complete.

A looping workflow can also be created using this technique, as the final step of the workflow involves updating data in the current item (setting the [workflow_started] back to "no"), which will trigger a new instance of the workflow. If your SharePoint environment is running at the Service Pack 2 level or higher, an "On Change" workflow will not start a new instance of the same workflow when the current item is updated. To enable looping functionality when Service Pack 2 is installed, you will need to use an intermediate list which is used to trigger a newworkflow in the main list. See SharePoint Looping Workflow - How to: Loop through and process all items in a list for more information about how to configure looping workflows with Service Pack 2 installed and how to configure a Looping Workflow. For more information about looping workflows, and some scenarios where that can be used such as a looping timer workflow, see article (Looping) Timer Workflows Using SharePoint. The article describes how a looping workflow can be used to send periodic reminders or similar when certain criteria has not been met.


The example above has two condition/action branches, one which tests if a task in a separate list is complete, and the second tests if the "Project Code" and "Assigned To" fields of the current item have been filled. When the conditions are satisfied, theworkflow continues to Step 2 where a field is set in the current item to prevent new instances from starting. Step 3 until the final step will include the main functionality of theworkflow. The final step will involve resetting the field in the current item to indicate that the workflow is no longer running, or complete.

Note: You will need to create a relationship between the current list and the Task list, or develop some method of being able to select the correct task item from the task list. Alookup column in the task list pointing back to the current list can be a good way to link one or more task items to an item in a separate list. Alternatively, the ID of the Task item may be able to be stored in a field in the current item if known. When aworkflow needs to refer to the separate item, it can then find the item using it's unique identifier which will help prevent the workflow selecting the wrong item.

If you are storing the ID of a separate item in a workflow variable or a field in the current item, you will need to use the "List Item ID" workflow variable type, or a Lookup column to retain a relationship between list items. Workflows developed using SharePoint Designer should use the Lookup/List Item ID column/field data types to when selecting items using their unique identifier. In most cases, SharePoint Designer will not allow you to select an item from another list using the unique identifier used by SharePoint unless you use the Lookup/List Item ID data types.


Related Articles:

SharePoint Looping Workflow - How to: Loop through and process all items in a list
"The OOB workflow actions provided by SharePoint don't allow a loop to be configured explicitly. Instead, a number of workflows can work together to create a looping affect. Another limitation of Workflows in SharePoint using SharePoint Designer (SPD) is the inability to simply test if the user who initiated the workflow is a member of a SharePoint group, or to test if the value of a field in the item which initiated the workflow is equal to the value of a specific field from any item in a separate list."


SPD Workflow - Test if value exists in any item in SharePoint list - create new item if not found
SharePoint Designer Workflow: How to test if a specific value exists in any item in a list without the workflow stopping due to a "List item not found" error if no items exist with the required value.

How to configure a workflow to start at specific time, then loop / repeat periodically (Daily, Weekly)
The following method can be used to start a workflow at a specific time, then repeat periodically (each day). Periodic Workflow Processing: (send daily email notification or reminder)A useful implementation of this technique allows you to configure workflows to run as background tasks at a specific time instead of being triggered by a user manually, or after creating or modifying a list item.

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.

SharePoint Workflow Errors: Descriptions, resolutions and Workarounds
The following table lists some of the common errors that can occur in a Workflow developed using SharePoint Designer. A short description of some of the likely causes for each error are also provided.

Service Pack 2 prevents an on-change workflow from starting itself