1

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.

Smiley
  • 3,207
  • 13
  • 49
  • 66
  • I'm confused by your sample code - where did it come from? – billinkc Aug 20 '20 at 22:25
  • This is actually what i'm using when my object only has one column in it. But since i changed my variable to multi-column, I don't know how to get to the columns and assign each to the two local variables. – Smiley Aug 20 '20 at 22:35
  • 1 - as far as I know, javascript is not a choice in a Script Task (only C# or VB.NET) so the tag confused me. 2 - The task.run I think is the async stuff which I guess I take your word that it works this way but it seems an incomplete example. Backing up a step, how did you push results into User::MyObject? An Execute SQL Task or some other mechanism as it may have a bearing on how we address members/properties. Also, if Execute SQL Task - full result set or Single Row? – billinkc Aug 21 '20 at 00:44
  • Sorry. I should have mentioned that I'm also using COZYROC that's why I got the JavaScript Task. I am using a SQL Task to push data into User::MyObject and yes, it is a full result set. At first, it was a single row because then I was only returning one single row and a single column. I'll edit my question to try to be a little more descriptive. Thank you. – Smiley Aug 21 '20 at 16:33

1 Answers1

0

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

vvvv4d
  • 3,881
  • 1
  • 14
  • 18