Updating a record from within a Javascript Step

Avatar

Avatar
Validate 10
Level 2
eriku40433679
Level 2

Likes

10 likes

Total Posts

33 posts

Correct reply

2 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile

Avatar
Validate 10
Level 2
eriku40433679
Level 2

Likes

10 likes

Total Posts

33 posts

Correct reply

2 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile
eriku40433679
Level 2

07-02-2018

Hi guys,

I'm trying to perform some string manipulation on the result set of a previous query. I'm using an intermediary Javascript step to contain the logic.

var schemaName = vars.targetSchema.substr(vars.targetSchema.indexOf(":") + 1); 

logInfo(schemaName);

 

var query = xtk.queryDef.create( 

  <queryDef schema={vars.targetSchema} operation="select"> 

    <select> 

      <node expr="@id"/> 

      <node expr="@description"/> 

    </select> 

  </queryDef> 

); 

result = query.ExecuteQuery(); 

 

 

for each (var e in result) { 

     logInfo(e.@description + e.@id);

    

     // manipulation and assignment logic goes here

     // db update logic goes here

}

// better if the db update goes here and is batched

I'm able to retrieve the fields from the previous step and print the columns out. I'm also able to perform the manipulation required on the description field but I can't, for the life of me, figure out how to SET and UPDATE the field in question.

Should I use a separate sqlExec call using an update sql query as it iterates over each item? Feels a bit inefficient and 'baking' in the string values directly to the sql query seems wrong and dangerous...

Many thanks.

Cheers!

--Erik

View Entire Topic

Avatar

Avatar
Validate 10
Level 2
eriku40433679
Level 2

Likes

10 likes

Total Posts

33 posts

Correct reply

2 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile

Avatar
Validate 10
Level 2
eriku40433679
Level 2

Likes

10 likes

Total Posts

33 posts

Correct reply

2 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile
eriku40433679
Level 2

08-02-2018

Excellent. Thanks Amit! Works like a charm. Hard coded the schema name as per your inline instructions and it works just fine for this specific workflow.

I'd like to know if there's a way for me to use the schemaName variable I've already extracted on the first line to make the collection variable a bit more flexible?

Cheers!