The other day I was struggling to get my Sharepoint Workflow working in the way I wanted. All the examples that I was able to find in books were all simple – one list, perhaps two lists, and a simple lookup. Easy stuff. But my scenario was slightly (I mean only slightly) more complicated – my second list had a reference to itself so needed a second lookup.
Well, Good News!
I read an interesting blog at http://www.sharepointassist.com/2009/05/09/handling-lookup-columns-in-a-sharepoint-designer-workflow/ by Ulysses Ludwig in which he gives an example of doing something similar. In fact, he is not doing the double lookup but his explanation is so clear and concise that it opened the doors of understanding, and I was able to take that and use it to develop my solution.
The key to the solution was in understanding how WSS handles lookups and connections to other lists. The key finding being that the first part of the Define Workflow Lookup (the bit titled “Lookup Details”) tells the system where the data finally comes from, and the second part of the DWL (titled “Find the List Item”) is the bit where you link the two lists together. And you do that by naming the list and the column for both lists.
So in the HolidayRequest list I take the “Name” field and do a lookup on that in the “Staff” list. That gives me the Staff record for the person making the request. In that record in the name of their manager – so I take that and store it in a Workflow Variable (called Variable:ManagerName.
So far so good – but that only gets us the manager name.
The next stage is to use the manager name from the Variable:ManagerName to do a lookup in the Staff list again but this time we get the manager’s Staff record. And, of course, in that record is the email address for that person. I store the email address in another Workflow Variable (called Variable:ManagerEmail) and hey presto! Job done – I now have the original HolidayRequest, and the Manager’s Name, and the Manager’s email address.
So I can now send an email to the manager asking them to authorise, or decline, the Holiday Request.
Magic.