Search code examples
javascriptforeachssisresultsetforeach-loop-container

SSIS For Each Loop Through Result Set


I have an ADO.NET Data Source that returns the contents from my query. It's a single-column, multiple-rows result set and I need to loop through this result set and process each row individually through JavaScript. To achieve this, I am using a foreach loop container.

To test this out, I created a JavaScript function inside my foreach loop container to output an alert box with the result set's contents.

I have the following simple test code:

task.run = function () {
    var myObj = task.variables["User::MyObject"].value;
    alert(myObj);

    return ScriptResults.Success;
};

I know the loop works well because the number of alerts I get is also equal to the number of rows I'm expecting. However, it seems that my JavaScript function is not reading the actual return value from the database. The alert just pops up as an empty string. I'm not sure if how i'm calling the object within my JavaScript is correct but I would really appreciate it if someone can point me in the right direction as to how to make the actual row value appear in the alert box.

Thank you!

EDIT: I'm using the Foreach ADO Enumerator for the ForEach Loop Container.


Solution

  • Specify variables under the Foreach Loop Editor's "Variable Mappings" for each of the columns in the source dataset. Then, reference that variable in your code. Don't reference your ADO object source variable.