Document Management With SharePoint - Part 3

Written By: Knox Cameron -- 8/24/2011 -- join -- contribute -- (2490) comments -- printer friendly version

Rating: Rate --

Categories: Design, Document Management, Features, Integration with other products , Programming and Customizations, SharePoint 2010, SharePoint Foundation 2010, Workflow

< Prev - 1 | 2 | 3 | 4 | 5 | - Next > | Become a paid author

Another way to get more information from SharePoint

You will have noticed from the screenshot of the library near the top of the article that there is a Client:City column. Client is a lookup to a Clients list. When the user selects a client, SharePoint fills in the Client column with the title of the client and also the Client:City column with the city of the client from the Clients list. This kind of additional lookup is new in SharePoint 2010, and is very useful as a way of showing more information from another list. However, unfortunately it is not provided as property in Office on the desktop.

This is a shame, because there are scenarios where this could be very useful. For example, let's say the Clients list included the client's address. We could then have Word set up so that when you select the client for the document, the client's address would be automatically filled in.

SharePoint calculated fields are great for classifying documents using rules based on values in other columns. However, they also are not available as Quick Parts in Word.

In part 1, we also included the consultant picture in a view by setting an option on the column in the list. However, this picture ended up in every view that included that column. We found a way to remove it from a view using SharePoint Designer, but that particular customization then causes an error if you ever need to change that view again in the browser. If that customized view is the default view of the library, that same error surfaces with other activities that try to customize the default view such as creating a column or running a new workflow.

So what approach can we use to get around these issues? Enter workflows.

A workflow can go and get the client's city (and address and other information) from the other list and put it into a normal column that you can use in Word.

A workflow can act to set a value based on rules like a calculated column does, but do it to a normal column which you can reference in Word.

And a workflow can go and get the consultant's picture or other information into a separate column, which you can then easily include or exclude as required in views.

Let's create a "Quick Step" workflow which will be available on the toolbar in the library in SharePoint. First, we will get this workflow to retrieve the city for the selected client and put it into another column in the library.

  • For production use, you could have a workflow that runs automatically whenever a document is changed, to save the user having to select the Quick Step button.
  • A limitation of using workflows is that the information will not be available in Word until the document has been saved into SharePoint for the first time and the workflow has been run.

Let's create a workflow to do this lookup in a fresh document library. Go to Site Actions -> View All Site Content. Select Create, then select Document Library. Call the library "Workflow demo" and select Create.

In the new document library, we will create two columns. The first will be a simple lookup to the Clients list. Select the Library tab in the ribbon and select Create Column. Name the column "Client", type Lookup, description "Select the client for which this document is prepared". Select to get information from the Clients list using the Title field.

Dialog to create Client column

Select OK. Now create a column in the document library to hold the client city. Name the column "ClientCity", type Single line of text, description "Use the Lookup City quick steps to fill in this information".

Dialog to create ClientCity column

Select OK to create the column.

To create the Quick Step workflow, select New Quick Step in the Customize Library group on the Library tab of the ribbon.

New Quick Step option in document library ribbon

This will launch SharePoint Designer (SPD) on your local computer, so the browser may give you a security warning. SPD will then display a form for you to enter information about the workflow. Leave the option "Start a new workflow" selected, and enter the button label "Lookup City".

SharePoint Designer requires you to have an image to use for the button in the ribbon. Ideally this should be 32X32 pixels in size. I am going to cheat and use one of the built-in images that comes with SharePoint. On the server, they are located in the "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES" directory, but from the point of view of the browser they are in the site in the path "_layouts/images". You can't use the Browse button in SPD to find them, so you will have to manually select one on the server and type its name into the dialog with the browser path. In this case, I am using a server image called "ctom32.png".

SharePoint Designer dialog for quick step button

Select OK to create the Quick Step button and associated workflow.

SPD will now take you into the workflow designer.

Empty workflow designer screen in SPD

This workflow needs to find the relevant information from the related list, then put it into the column we created ready for it in this list. You can do this in a single step, although it's a complicated one!

From the Action drop down in the ribbon, select Set Field in Current Item. SPD will fill this into the workflow designer, with underlined placeholders for "field" and "value".

Set field in current item with placeholders

Click on the placeholder for field. From the drop down, select the column we created for this purpose "ClientCity".

Drop down options for field 

Now click on the placeholder for value. The placeholder turns into an entry field, with two buttons next to it: an ellipsis (three dots), and a function sign (fx).

Entry field in placeholder for value

Select the function sign button.

(This is where it gets a bit complicated!)

First, SPD wants to know where the data is coming from (the Data source), and what column to retrieve. The Data source drop down shows various workflow-related options (such as current item and workflow variable), then lists the other lists in the site. Scroll down and select the Clients list as the Data source. As soon as you do, the dialog will expand with more options.

The second drop down "Field from source" will now show the fields in that list. Select the City field as the field you want to retrieve.

Lookup dialog with data source list and field selected

We now need to tell the workflow how to pick which entry in the clients list it should be using to find the city. To do this, we will use the lookup field in the document library that points to an entry in the clients list.

Lookup fields store both the ID of the item to which they are pointing and the text value. The ID is the best thing to use, because it is simple and guaranteed to be unique. So we will tell the workflow to find the entry in the clients list which has an ID which matches the ID stored in the Clients lookup column for the current document (item) in the library.

Under the Find the List Item heading, click the drop down for Field. Select the field "ID", because this is the column in the Clients list we are matching. For the Value, click the function button next to the entry field. Another dialog pops up called "Lookup for Integer". This is because SPD knows that ID is an integer, so we should be selecting something that returns an integer.

Leave "Current Item" selected as the data source and select the field Client. For Return field as, select "Lookup Id (as Integer)".

Dialog to select source for ID of lookup

Select OK. This now completes the lookup dialog.

Completed lookup dialog for workflow

Select OK to save the lookup information. After all that, the completed workflow step looks deceptively simple!

Completed workflow with one step

Click the Publish button in the ribbon to both save and publish the workflow. (When you save a workflow, it is like saving a draft. To run the workflow, it must be published.)

Go back to the document library, but leave SPD open with the workflow so we can add more steps to it later on. Upload a test document. When you are prompted for metadata, select a client, but don't enter anything for the ClientCity column.

Setting the client for a test document

Back in the library, select the check box next to the new document in the list. On the Documents tab in the ribbon, you should see the new Lookup City quick step. (If you don't, refresh the browser and try again.)

Document library showing quick step in ribbon

Let's try running it! Click the Lookup City button. A workflow initiation form is displayed.

Workflow initiation form screenshot

If we were building a more elaborate workflow, we could use this form to ask the user for information to use in the workflow. Click Start to launch the workflow on the selected document.

Workflow processing screen

< Prev - 1 | 2 | 3 | 4 | 5 | - Next >

Learn more about SharePoint

Sponsor Information

Copyright (c) 2010-2017 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | contribute | feedback | about
Some names and products listed are the registered trademarks of their respective owners. |