0

I have a SSIS package with 4 Sequence Containers. Each one of them has a Script Task. I want to capture the Name of the container from inside the Script Task code. How can I do that? I haven't found a way to access parent objects.

I've currently implemented this with variables, as commented by @LONG. My issue is that because each container is exactly the same (i.e. it contains the same tasks and code), when I do a change, I only do it in one of them, then delete the other 3, and copy/paste the one with the updates. So, with the variable implementation I will need to do more changes after the copy/paste part which I could avoid by reading the container Name

Cesar Vinas
  • 343
  • 1
  • 10
  • 20
  • It's rather hacky but building on the System::ParentContainerGUID, you could have a script task open the package via the SSIS object model and then look through the Tasks for that GUID and pull the name property from there. Biggest challenge would be that a script task doesn't have access to the package at large so you'd need to pass in the location of the .dtsx and then this approach gets ugly if it's in the msdb or the SSISDB instead of the file system – billinkc Mar 28 '17 at 21:57

1 Answers1

1

You could use Variable to achieve that.

In your case, define another four variables for storing container name, and name them in the value filed.

Then go to the properties page of each container, expand the Expression, set the Name equal to corresponding variable, after that you could find the container name has changed to that value name.

Finally, you could use that variable as read-only or read-write in your script, which is identical to the container name.

UPDATE:

If you think that is way too complicated and time consuming (it is not), you could use one system variable named System::ParentContainerGUID to uniquely identify each container, even if you copy and paste from the same container, if will generate a unique ID string for that one. But this is a string with random character, unlike the actual name.

LONG
  • 4,490
  • 2
  • 17
  • 35
  • That's exactly the way I've implemented it for now. My issue is that because each container is exactly the same (i.e. it contains the same tasks and code), when I do a change, I only do it in one of them, then delete the other 3, and copy/paste the one with the updates. So, with the variable implementation I will need to do more changes after the copy/paste part which I could avoid by reading the container Name. I'm going to update my question because i should've explained this part too – Cesar Vinas Mar 28 '17 at 17:57
  • Inside the script you can access the value of ParentContainerGUID using Dts.Variables["System::ParentContainerGUID"] – observer Apr 27 '17 at 10:55