I wanted to get a better grip on Parameters so I decided to set up a simple example using parameters to configure a File System Task. My thinking was that it would be a clean, and simple, process that would lead to a happy place and a couple of really easy examples. But, no chance of that.
So, here was the plan, set up 8 parameters for a File System Task and run it in a couple of different places. The process would consist of
- Creating a file and folders for the demo.
- Configuring parameters.
- Using expressions to map the parameters to the task.
- Run the task.
- Call it a day.
I’m skipping the create a package / project instructions. I’m going to assume that you know how to do that, by now.
Step 1: Create the files to move.
This is what I did, you are welcome to do whatever else you like. I created the following 2 folders and a file.
This went just fine.
Step 2: Create parameters.
My first attempt looked like the following. We’ll be revisiting this screen, soon.
Step 3: Map the parameters to the File System Task using the expression editor.
This looked like the image below.
Step 4: Run the package.
And the fun began.
The first error is actually two errors. Because I had set the initial IsDestinationPathVariable, and, IsSourcePathVariable parameters to True, the package is actually looking for variables, not parameters. My first attempt at fixing this was to set these values to False, however, that threw an error because it was looking for a connection, and, c:\testData\backup is not a connection.
The solution to this involved 3 things.
First, I set the IsDestinationPathVariable and the IsSourcePathVariable set to true.
Next, I create two string variables, varSource and varPath, which I configured as follows:
Then, I configured the parameters to point to these variables, which meant that my parameters tab looked like this.
Life was good, it was time to run the package, and move on.
And then this happened.
Error: The result of the expression “@[$Package::Operation]” on property “\Package\My Move Demo.Properties[Operation]” cannot be written to the property. The expression was evaluated, but cannot be set on the property.
This error didn’t help, much, but the word Operation got me to look in the expressions and click on the expression I was using to set the operation property. It turns out that this property is an Int32, not a string. That’s actually logical as Select boxes contain a selection that is presented to you and then sets a value for your selection that is almost always different than the description that you based your selection on.
So, I reset the parameter to an int32, looked at the list, saw that Move File was seventh on the list, and set it to 7. Nope, that is “Move Directory”. Ah, maybe it starts at 0? So, I set it to 6. Nope, that’s “Copy Directory”. Finally, I just started rolling through them until I discovered that “Move File” is 1.
And happy days.
This is my working parameter tab.
And the File System Task
And that is a working set of parameters, tied into a task using expressions, that includes linking 2 parameters to variables. I had planned to do more with this, and I will, but this post is plenty long. If by some crazy chance you work through these, then you should save this as a package. We’ll be visiting it in my next post.