Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

How do I add a field to a temporary table in a workflow?

Avatar

Level 3

Hi

I have a simple query which returns 1 column

I want to take each value from that column, do some JS stuff to it, then keep the result for each row to use in later stages of the workflow (for filtering/splits/etc)

The below works to get me to the value I am looking for, but I am unsure how to write the result back into the table?

Any advice appreciated, cheers

Stephen

Object.defineProperty(String.prototype, 'hashCode', {
 value: function() {
 var hash = 0, i, chr;
 for (i = 0; i < this.length; i++) {
 chr = this.charCodeAt(i);
 hash = ((hash << 5) - hash) + chr;
 hash |= 0; // Convert to 32bit integer
 }
 return hash;
 }
});

var query = xtk.queryDef.create(<queryDef schema="temp:query" operation="select"><select><node expr="pid"/></select></queryDef>);
var resultSet = query.ExecuteQuery();

for each(var row in resultSet) {
  instance.vars.pid2 = Math.abs(row.pid.toString().hashCode())
  logInfo(Math.abs(row.pid.toString().hashCode()))

  };

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 9

Hi @stephenjwz Have a look into this sample code - it explains how to select some records, modify some values and then write back to the temporary schema: https://technowide.net/2017/05/19/iterating-custom-functions-record/

If you have a lot of records i.e. > 10K, then you will need to page the record set select/write operations: https://experienceleaguecommunities.adobe.com/t5/adobe-campaign-classic-questions/advanced-workflow-...

Note: if you need to do recordset paging, you cant write back to the temporary workflow schema - it wont work. It doesn't page correctly. You need to create a temporary schema and write back to that and then enrich the temporary schema back into the main schema later on.

View solution in original post

2 Replies

Avatar

Community Advisor

Hello,

I am not sure if you can do it directly in JavaScript..But when I do this kind of a "operation" i create all the fields i need in the enrichment activity beforehand where you fill the alias for easier selection in expression leave '' and then do the same thing you doing in JS

 

EDIT:

Also you can do by it executing SQL code in SQL activity or you could use JSAPI function sqlExec()  and altering the temporary table   'vars.tableName' by adding the columns you want. 

 

 

Marcel

Avatar

Correct answer by
Level 9

Hi @stephenjwz Have a look into this sample code - it explains how to select some records, modify some values and then write back to the temporary schema: https://technowide.net/2017/05/19/iterating-custom-functions-record/

If you have a lot of records i.e. > 10K, then you will need to page the record set select/write operations: https://experienceleaguecommunities.adobe.com/t5/adobe-campaign-classic-questions/advanced-workflow-...

Note: if you need to do recordset paging, you cant write back to the temporary workflow schema - it wont work. It doesn't page correctly. You need to create a temporary schema and write back to that and then enrich the temporary schema back into the main schema later on.