Slinger's Thoughts

April 23, 2008

Updating items created by a workflow in a tasks list.

Filed under: SharePoint — Tags: — slingeronline @ 6:46 am

Microsoft has an article about how to use a workflow to create an item in a tasks list from a discussions list here.  The tutorial is good. It’s simple, easy to follow and understand, but something isn’t right with it.  This will indeed create an item in a task list, but what if you want to have the status of this task update back to the list it was created from?  Well, I ran into a situation like this, and getting a workflow to work recursively isn’t easy.  Microsoft’s original article is actually wrong.  Creating a task this way doesn’t alert the user or users the task was assigned to.  And there is no update to the list that the task was generated from as to whether the task is complete.  I had to fix that.

Here’s what I wanted to do, and what I wound up doing.  First, here is what our problem was, and our proposed resolution.  In our IT department, we are constantly tasked with setting up users’ phones, computers, and e-mail accounts.  We have two local offices, and about four field offices. When an employee is hired, we have to add them to our phone system, create an e-mail account for them, and assign them a computer.  When an employee relocates, (which happens often as our field offices are not ours but our customers’,) we have to change their phone setup, and their computer setup, so that they can access all the required assets.  One of my IT colleagues asked if we could do something like this in SharePoint.  Yep. We can, and I went to work figuring it out.   I created four lists; “Computer Setup,” “Phone Setup,” “Email Setup,” and “Action Items.” The first three lists are custom lists, and “Action Items” is a tasks list. Any time that an item was created in any of the first 3 lists, a workflow would create an item in the Action Items list, just like what was stated in the article.  I wanted to create another workflow that would update the originating list once the task was completed.  Now is where I started running into problems.  I needed a way to identify which item in each list was updated.  Say we get five new employees.  Five items would be created in each of the three lists, but that would create 15 action items.  If I wanted to use the item ID to identify each item to update, the workflow would be looking for an item number that doesn’t yet exist in any of those lists.  It simply wouldn’t update correctly.  There has to be another way.  Well I found that when you create a workflow a new column is created in your list that will show you the status of your workflow.  I was going to use that.  And instead of creating an item in a task list, I would use the workflow to assign a to-do item.  This had the benefit of alerting the appropriate users of a new task assigned to them, and the workflow progress column in the list the task was created from would simply say “In Progress” until the task was completed.  Once a user edited the task and clicked “Complete Task,” the workflow status in the list the task was created from would say “Completed” also.  Perfect.  And relatively simple.  Except that you cannot add details to the task created by the workflow.  This took some hunting, and eventually I found this site from Microsoft explaining what a “secondary” workflow is.  (Every time I would use the “Assign a to-do item,” in the workflow, I would get a message saying that I could specify details using a “secondary workflow.”) I think I had my answer now.  The downside to this is that We are going to create quite a few workflows.  We are going to create a workflow for each setup list, and probably two for the Action Items list.  The first workflow for the Action Items list is going to get the details from the list item that created the action item, such as the due date.  The second workflow for the Action Items list is going to watch the item and send an email if the task is not completed by the due date.  (I split these into two separate workflows, because when they are in the same workflow, the workflow status in the list that task was created from does not update when the task is marked “completed.”)

First I created the four lists I knew I would need, and customized them as needed.  A Phone setup list that included the following columns; Employee Name*, Extension, Old Office Location*, New Office Location*, and Due Date*,
 ScreenHunter_01 Jan. 28 08.27

an Email Setup list that included the following columns; Employee Name*, Department*, Old Office Location*, New Office Location*, Email address and Due Date*,

ScreenHunter_02 Jan. 28 08.33

and a Computer Setup list that included the following columns; Employee Name*, Computer Serial #, Old Office Location*, New Office Location*, Laptop (Y/N)*, and Due Date*. 

ScreenHunter_03 Jan. 28 08.36

Any column that I put an asterisk next to was a required column for information to be entered in.  Not all of the changes we need to make were for new employees, which is why I have the office location columns.  And not all of the employees are current.  If we have not set them up in the AD, then we can’t use the people picker in SharePoint to populate the Employee Name column, so I left this as a plain text column.  Well, one of the things that you will notice right away is that obviously all of the lists don’t contain the same information.  We could create 3 different tasks lists, but that would just be silly.  You can choose to populate your lists however you want.  I created another list for office locations to choose from, but you don’t have to.

Now we open SPD to start creating the workflows.  The first ones are simple and straightforward.  For each “setup” list, we set a workflow to start each time a new item is created. 

ScreenHunter_04 Jan. 28 08.40 

Select “Assign a todo item” from the actions list.  

ScreenHunter_05 Jan. 28 08.42 

Click on the link marked “a to-do item.” This will start a small window that will ask you to name the to-do item. 

ScreenHunter_06 Jan. 28 08.45 

Click “Next.”

ScreenHunter_07 Jan. 28 08.46

Rename your task appropriately (“Computer setup” etc.) You can put a description here if you want. I didn’t. Click “Finish.” (This creates a new content type in your site.)

The next step of the action is to assign the task to a user. I selected the IT Dept from the SharePoint groups.

ScreenHunter_08 Jan. 28 08.53 

Do this for all 3 of your “setup” lists.  Once you add a new item to each list, you will notice a new column for workflow tracking in each list.  When you mark a task “completed” in the tasks list, this column will update from “In Progress” to “completed.”  That seems pretty simple and straightforward.  We could reasonably stop here, but I want each task to contain the detailed information for each list.

This is where it gets tricky. Each task that was created is fairly generic.  We want to populate certain columns in each task with the appropriate information, such as the Due Date, and the details.  We can do this with another workflow. (There’s workflow number four for those keeping count.)  This workflow we are going to attach to the Action Items list. 

ScreenHunter_09 Jan. 28 08.55 

We want it to check which list each task came from, and then grab the information in that list, so that it can apply it to the tasks list.  We will start this workflow automatically when an item is created.  We want to create two variables, one for Due Date, and one for Description (named DueDate and Desc.).  We are going to pull all of the pertinent information to put into the Task’s description, and assign the due date to the task.  Since we are going to get this information from three different lists, we will need three conditional branches.  For each one, We want to compare a Task list item field.

ScreenHunter_10 Jan. 28 12.47

Click on “Field” and select “Workflow Name” from the dropdown box.

 

Since each setup list we created has a different workflow name, that is what we want to check.  Type in the workflow name as you entered it when you created the workflow in each setup list.  So now our conditions should read “If Workflow Name equals Phone Setup” which is what I named my Phone Setup workflow. (Not much for convention, I know, but it makes sense.)

ScreenHunter_11 Jan. 28 12.50

  Now we need to capture the information from that list.  From that actions menu, select “Build Dynamic String” and click on “dynamic string” in the new action created. 

ScreenHunter_12 Jan. 28 12.51

ScreenHunter_13 Jan. 28 12.52

This will open up the string builder. 

ScreenHunter_14 Jan. 28 12.53

Click on “Add Lookup.”  This is where we are going to select the information to pull from the setup list.  From the top “Source” selection field, select the appropriate list that we want to get the information from.  The from the “field” drop down, which field we want to get.

ScreenHunter_19 Jan. 28 13.15

The tricky part is under the “Find the List Item” area in the bottom.  We want to tell the workflow which item to snag.  So set this to “(list name):ID”. In my current case, “Phone Setup:ID.”  For the value drop down, select the fx button (I forgot what the damn button is called), and for Source, leave “current item” selected.

ScreenHunter_20 Jan. 28 13.15

For the field drop down, scroll all the way to the bottom and select “Workflow Item ID.”  Click ok.  Now in our define Workflow lookup window, the fields should look like the following, Source = Phone Setup, Field = (the field we want to get), and under “Find the List Item,” Field = “Phone Setup:ID” and Value = “Tasks:Workflow Item ID.”  Lather, Rinse, Repeat as necessary.

ScreenHunter_21 Jan. 28 13.16

Once we are done building our dynamic string, (I’m still working on the formatting there.) We want to store this in our description variable. 

ScreenHunter_22 Jan. 28 13.17

Next we want to set the due date of the task item.  Similar to before, but instead of building a dynamic string, select “Set workflow variable” from the actions list.

ScreenHunter_23 Jan. 28 13.20

Set the Due Date variable to the Due date in our Phone Setup list.

ScreenHunter_24 Jan. 28 13.20

Just like we did for the dynamic string variables, we want to go through the same steps to select the due date from the phone setup list to apply to our Tasks list.  Apply another action to “Update list item.”  Leave the list selected as “Current item.”  We need to tell the workflow what data we want to put here.  Click the “Add” button.  In the “Value Assignment” window, under the “Set this field:” drop down, select the “Description” field.  For the value to enter, click the “fx” button again. This time though, for “Source” we want “Workflow data”, and for Field, we want to select the appropriate variable that we created.  Click “OK.” Click “OK” again.  Now repeat for the Due date for the task.  Now when a new task item is created, this workflow will check, and if it was created from an item in the Phone Setup list, the task description and due date will be set according to what the information was in the Phone Setup list.  Nifty! We need to do the same for the other two lists though, which is why we added the condition at the very beginning.  We need to know which list, to update from, and how to build our dynamic string based on those lists.

I’ll wait a few minutes while you go and add the other two lists to the workflow….

So now we have three setup lists, and a tasks list, a workflow for each setup list that creates a task for our users, and a workflow for the tasks list to get the details of each task from each list.  The last thing we want to do is to create a workflow to send a reminder to the users the task was assigned to if the due date hits.  Interestingly enough, this will need to be handled by another workflow.  I tried adding is as a step to the details workflow, but that had the interesting effect of interrupting the workflows that assigned the tasks to the task list, so that when a task was completed, the workflow status in each setup list wouldn’t update and would still say “In Progress.”  That’s ok, we’re getting pretty good at building workflows by now anyway.  For those keeping count, this will be workflow number five in our site.

For this workflow we will have two steps. In the first step we will set a variable to keep the due date and then pause the workflow, and in the second we will check the status of the task, and send a reminder e-mail if needed.  Go ahead a create a new workflow, name it, and have it start when an item is created.  Create a variable called “Due Date.” Click on the “Actions” drop down in the first step, and select “Set workflow variable.”  The variable we want to set is the one we just created, and we want to set it to “Current Item, Due Date.”  Click on the actions drop down again, and select “Pause until date.”  For the source, select “Workflow Data” and the variable we just created.  All this does is tell this workflow when it needs to start working.  On the right hand side of the Workflow Designer dialog, under “Workflow Steps,” click “Add workflow step.”  Here we are going to check the status of the task, and if it’s not complete, we are going to send an e-mail to our users.  Click on Conditions, and then “Compare Tasks field.”  Select the status field, and then select “Completed” for the value it should equal.  Click on the Actions drop down, and select “Stop workflow.” The workflow will want to log a message.  This can be anything you want, since the only people who will likely see it are the ones looking at the workflow history.  Mine simply says “Task Completed.”  Good enough.  Add an Else If branch, and then click on the Actions drop down.  Select “Send an e-mail.”  Click on “This message.”  This brings up a dialog similar to our dynamic string builder, but with a few more options.  In the “To:” field, click the address book icon, then click on “Workflow Lookup” from the selection screen.  This pops up our workflow lookup dialog.  (It should look familiar by now, we’ve seen it a few times.)  For the source leave current item selected.  For the field, select “Assigned To.” Click OK twice. For the Subject field, we want this to be something that will make sense to our users, so click on the “Fx” button to the right.  Again, leave the source as current item.  For the field select “Name (for use in forms).”  This will put the title of the task as the subject line in our e-mail.  Then compose whatever e-mail you would like to send.  I also included a link to the task using the “Add Lookup to Body” button.  I’ll let you tinker with this one to workout however you want. 

And that’s it.  So now we have three lists, one for phone setup, one for e-mail setup, and one for computer setup for our employees, and a tasks list for out IT department that catches information from all three of these lists, and a friendly reminder if the IT department slacks off.  Knowing how to use the Workflow Item ID has helped.  The only thing I have left to do is to figure out how to format the dynamic string properly. (For some reason, I can’t get mine to put each field on its own line, instead of all mushed together.)

My screen capture software isn’t working, otherwise I would have images to go along with this post.  If anyone wants to, feel free to get some screen caps and I will post them.

Update! My Screen capture software is working again and I have uploaded some screen shots of working through the difficult part of this solution.  Hope it helps.

Advertisements

12 Comments »

  1. sharepoint sucks!

    Comment by sharepoiint sucks — June 26, 2008 @ 11:44 pm

  2. fuck microsoft and the developers of this twatttt!

    Comment by sharepoiint sucks — June 26, 2008 @ 11:45 pm

  3. apparently someone doesn’t like SharePoint. Although I’m not sure what could be used instead that has as many bells and whistles that are actually useful… Spsucks, feel free to offer us your alternative views. We like to know what you have to offer. Or maybe there was something you were trying to do and haven’t been able to. Go ahead and ask, and the other readers or myself may be able to offer you options or resources for help.

    Comment by slinger — July 1, 2008 @ 6:47 am

  4. thanks so much for the detailed and well explained solution. it is exactly what i have been trying to build and your explanation on secondary workflows was really useful.

    i still think ssp designer workflows are pretty limitting – I couldn’t find a place where I could delete the “list names” for test workflow to-do items that i used for testing (e.g. I used Windows Acc as a name and then couldn’t reuse it even though I deleted the whole workflow). but it will have to do in the absense of knowledge of visual studio.

    Comment by grechka — October 6, 2008 @ 10:29 pm

  5. silly me, I figured out how to delete them and again with your help – they are content types! so I just went to site settings and deleted my stupid test custom content types.

    Comment by grechka — October 6, 2008 @ 10:40 pm

  6. glad it worked out for you grechka. (I had to go through figuring out it was the content types on my own.)

    Comment by slinger — October 7, 2008 @ 5:53 am

  7. it could’ve been better if there’re really images to support the long explanations. ^^
    i’m still loving the old .net development where you make it look more like sharepoint-ish..
    sharepoint oob sometimes sucks.

    Comment by jeiku — October 28, 2008 @ 1:46 am

  8. I would love to have images, but my screen capture thing doesn’t always cooperate. I will try harder in the future.

    Comment by slinger — October 28, 2008 @ 6:02 am

  9. Hi, I used your logic example, but the workflow data variable doesn’t display as an option to update the field which I want to set in the workflow’s task list…

    I tried looking up several fields from the document library list, and no option made the variable visible in the list of options under ‘current item’ workflow data.

    I know you are using Custom Lists, and I am using a customized document library. I’m not sure why that would make a difference…

    Any suggestions?

    Comment by Elaine — January 13, 2009 @ 6:17 pm

  10. Elaine, I’ll have to look into that. I think I did something recently where it did show up. It’s been a while since I set this up.

    Comment by slinger — January 14, 2009 @ 7:10 am

  11. hi,
    can you email me the same details included with images please?

    I have one List created, for that I created one Assigned-to item in workflow. hence, it created on Task Item under tasks list. I want to rename the title of the task item to the title which I stored in the workflow variable. Is that possible using with Update Item Action?
    can you please gimme detailed explanation for this. if possible send me an email with images.
    any suggestions on this?
    awaiting for your reply.

    Thank you

    Comment by Kalyan — January 27, 2009 @ 10:03 am

  12. any clues please??

    Comment by Kalyan — January 28, 2009 @ 11:00 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: