Wednesday, March 30, 2011

Embedding a link to a printable list item in a workflow email.

When you create a workflow based on a list item, such as sending an email after an item has changed, it is useful to have a link within that email that links back to the list item. It would be even better to have a link back to a printable version of that list item.

The default link creation tool in SharePoint Designer workflows however doesn't work. If you attempt to add a link using the SharePoint designer field created for that purpose, you will end up with a link that connects do nothing and doesn't work.
So how do you create a link back to the list item that does work, with a printable version of the list item?

Open your existing workflow or create a new one.

Set up all of your conditions as necessary, and then set up the "Send Email To" action, filling out fields as appropriate.

In the body of the email, to link to the original list item, do the following:

1. Type in the text in your email that will be the link to your item, such as "View Test Case" or "View List Item". Highlight the text and click the hyperlink button.

2. "Text to display" will already be filled out if you highlighted your text, if not, fill out the text you wish your link to be associated with. Then, in the address section, click the String Builder button (3 dots).

3. Build the link in the following way:
- Start with the URL of your SharePoint server, egs. https://yoursite.gov.bc.ca. Note the lack of trailing slash.
- Click "Add or Change Lookup"
- In the data source field, choose "current item".
- in the field from source field, choose "Path"
- Leave the "return field as" field to its default, "As String"
- Click ok to build the first part of the url
- Append the following text to the URL "/DispForm.aspx?ID=" This must be EXACT including the beginning slash
- Click "Add change or lookup"
- Data source is current item
- Field from source is "ID"
- Click OK.

The URL that you have created should now look something like:
https://yoursite.gov.bc.ca[%Current Item:Path%]/DispForm.aspx?ID=[%Current Item:ID%]
Ensure all slashes and naming of the DispForm part are IDENTICAL.
Click "ok" then "ok" again.

Your workflow email will now have a link that links to a printable version of the list item.

Thursday, March 3, 2011

Triggering workflows on lookup fields

When you create a "choice" item associated with a SharePoint list, it is relatively easy to associate that choice with a workflow. You simple create the workflow, and in the condition portion, you select the choice field you created, and in the value column, you can select the choice that you wish to trigger the workflow on, for example:

If Current Item:Status equals (1) ready
Email steveburgess10@gmail.com

This is nice and easy. But what about the case where a lookup is used to populate the choice dropdown menu? If I have a seperate list that I wish the lookup to use, as shown below, then the approach needs to be different.



Comparing the lookup field value with either the ID of that field or the text of the field both fail, for example:

If Current Item:Dynamic Status equals (1) ready
Email steveburgess10@gmail.com

does not work. Even using the ID of the field (retrieved from the lookup list) does not work, for example:

If Current Item:Dynamic Status equals 1
Email steveburgess10@gmail.com

But we are close. The ID is the key. Here are the steps for correctly creating a lookup field that can trigger a workflow.


1. Within you SharePoint environment, navigate to the list you wish to associate the workflow to.
2. Click the "list" tab and then the "list settings" button in the office ribbon.

3. Click the link to your lookup field listed in the "Columns" section of the list settings page.

4. KEY STEP. As shown in the below screenshot, in the section titled "Add a column to show each of these additional fields", put a checkmark beside the ID value. This value is what will be tested against in our workflow.





















5. Open SharePoint designer and open the site that hosts the list you wish to associate the workflow to.

6. Choose the "Workflows" selection in the site objects collection, and select "List Workflow" from the choices provided.

7. Name and describe your workflow.

8. KEY STEP. Click the "condition" button at the top of the workflow page and select "if any value = value". NOT "If current item = value". While they result in identical looking code, using the second choice WILL NOT WORK. This will create your condition logic:

If field equals value

9. In the "field" selection that you wish to match against, choose the lookup list name:ID field. In my example, I am looking at the status field, so I am looking for the field value "Status:ID".

10. For the value, enter in the ID value that corresponds to the value of the lookup item you wish to trigger the workflow from. So, in my example, I know that the status ID of the status I am interested in is 4, so my condition looks like this:

If CurrentItem:Status:ID equals 4

Email steveburgess10@gmail.com

11. Add any fields or other information to the email that is generated, save and publish your workflow.

Associating workflows with lookup fields is not done in the same way as choice fields, as you cannot compare the selected values in the same way (such as a string compare). By extracting the ID value from the source list and including it in the destination list, you can compare that ID value to an integer value to successfully trigger the workflow.


Wednesday, March 2, 2011

Creating Default Values for lookup fields in InfoPath 2010

Creating a default value for a lookup field in SharePoint/InfoPath 2010 is not intuitive. When you initially create the lookup, there is no place for default value (as there is for non lookup selections) and when you open the form in infopath, and right click the lookup field, there is no option there to display a default value either.

This solution selects the default value on the creation of a new form record. It does not update existing records with no value selected to the default value.


Here is how to set a default value for a lookup:

Open the form in infopath.
Click the "File" tab ->
Click the "Form options" button in the "Advanced Form Options" section ->
Select the "Advanced" category (see screenshot 1) ->
Click the button "Edit Default Values" ->
Click the "+" on "myFields" ->
Click the "+" on "dataFields" ->
Select the lookup field you wish to set a default value for by clicking on it (see screenshot 2)->
Enter in the default value for the lookup field. Remember that the default value here is the ID of the record, not the name. See screen shots below ->
Click "OK" then "OK" again and first test functionality using "preview" button in infopath ->
Verify your lookup is now populating with a default value ->
Publish the form.

Screenshot 1, Advanced Form Options from file tab













Screen shot 2, Setting ID of default value