One of the great things about SharePoint 2010 is the ability to create reusable workflows. No more tying a workflow to an individual list or library. Now, you can tie a workflow to a content type, and reuse it in multiple list or library instances. Unfortunately, today I found what I think is a bug in using calculated columns in reusable workflows. Let me lay out the scenario.
- Create a test content type with the following site columns.
- Cost 1 (currency column)
- Cost 2 (currency column)
- Total Cost (calculated column with the function =SUM([Cost 1],[Cost 2]))
- Create a test list and set the default content type to be the test content type.
- Create a test reusable workflow (no steps needed yet), publish it, and attach it to the test content type.
Got that all set up? Great.
- Click “Association Columns” in the ribbon.
- Click “Select a Site Column.”
- Find your site column and select it.
We should be good to go! Now when you want to use the Association Column, it will show up as part of “Current Item” in your workflow.
Super easy, right?
Hold the phone. Nothing is ever quite THAT simple with SharePoint. What happens with the datatype of that Site Column?
Well, if this is a non-calculated column, you’ve got no problem. SharePoint Designer recognizes the data type of the column and asks you how you want to format it.
The same is true if you’re using a list workflow with a calculated column.
But, if you’re using a reusable workflow with a calculated column, you’re out of luck. SharePoint Designer will only return it as a string.
Worse yet, the string that is returned includes information on the data type – in the case of my currency column, the string returned is “float;#40.0000000000000.”
So, what do you do?
I’m guessing you could write some crazy string manipulation functions to handle the formatting of this weird string.
Or, you could try to set the value of the Association Column to an intervening workflow variable of type double. The interface will choose to return the Association Column as a double.
You could try that. But, it won’t work. It LOOKS like it will work. But, if you try to do it, here’s what you get:
Is anybody else getting the feeling this is a bug? No? Okay. Moving right along.
The Total Hack Solution
What I’ve found is that the easiest thing to do is to (if possible) is just replicate your calculations within SharePoint Designer. In my case, this resulted in a series of addition problems with intervening variables.
Barring that approach, I think your only option would be to use a list-based workflow on the list to update a secondary non-calculated column and firing that workflow before the reusable workflow. Of course, that completely defeats the purpose of having a reusable workflow.
Any body else have any bright ideas?