Search code examples
javascriptobjectssisssis-2017

SSIS Reading Columns from an Object Variable


I have an object variable which is from a SQL Query. This essentially contains two columns: RecordID and Description. I'm not familiar with JavaScript. But how do I read the specific columns and assign them to a local javascript variable?

Here's the sample code I would like to use with the new User::MyObject structure of multiple columns:

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

    alert(myID);
    alert(myDesc);

    return ScriptResults.Success;
};

EDIT: I am using COZYROC that's why I have a JavaScript Task available in my toolbox. The result set is currently set to Full Result Set and the object is being pushed to User::MyObject via a preceeding SQL Task.

Here's a code from when my User::MyObject was a single result set with single row and single column return (just the Description).

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

    return ScriptResults.Success;
};

I know for VB.NET/C# you can use something like myVariable.Rows[0][1].ToString() but i'm really not sure how that translates to JavaScript.


Solution

  • Within your task function:

    1. Set a variable to the object

    var MyObject= task.variables["User::MyObject"].value;
    

    2 Access the ID property of your object

    MyObject.ID
    

    Complete example to get ID:

    task.run = function () {
        var MyObject = task.variables["User::MyObject"].value;
        alert(MyObject.ID);
    
        return ScriptResults.Success;
    };
    
    

    Example from crazycroc documentation https://desk.cozyroc.com/portal/en/kb/articles/how-c