Expand my Community achievements bar.

SOLVED

Update instance variable with target data field.

Avatar

Level 3

Hi,

Apologies for the basic question but I've tried a thousand different variants and not come up with the answer myself. Also non of the documentation seems to address this. Getting this to work will close off this particular task I need to complete.

I want to create an instance variable and populate it with a field from my target data. I can successfully create and populate it with hardcoded text as below, however I need to to pull in a data field instead

instance.vars.AKTEST = "Campaign Name"

I want to replace "Campaign Name" with the field @campaignLabel which I have appended in a previous enrichment (please see screenshot).

I had hoped that instance.vars.AKTEST =  instance.operation.label would work but this simply returns a null value (if it did work then I would simply use the instance.operation.label variable when I required it later on).

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi Alistair,

You can do so by using queryDef API on the temporary schema created for Enrichment activity. Please follow the steps outlined below from the test I carried out. You can make changes as per your workflow.

  1. In my setup there is a query activity, followed by enrichment which is followed by JS code activity that will populate the instance variable with relevant data from Enrichment.
  2. Referring to attached screenshot, inside the enrichment I've generated a modified first name of recipient by appending the string " is my first name" to the existing recipient first name. So, John will be modified to "John is my first name" and will be tagged as newFirstName field. 
  3. Please see that the alias has been modified inside Enrichment output columns and the new field is called @newFirstName.
  4. Also referring to schema of enrichment the temporary table can be referenced using schema temp:enrich.
  5. Inside JS code activity, perform a queryDef call on this temp schema and then read from the relevant column.

Adding the code here for reference.

var query = xtk.queryDef.create( <queryDef schema="temp:enrich" operation="select"> <select> <node expr="@newFirstName"/> </select> </queryDef>); var resultSet = query.ExecuteQuery(); for each (var row in resultSet) { logInfo("From temp schema : " + row.@newFirstName); instance.vars.AKTEST = row.@newFirstName; logInfo("From instance variable : " + instance.vars.AKTEST); }

When my sample workflow is executed, the output is 

Hope this helps.

Regards,

Vipul

View solution in original post

4 Replies

Avatar

Correct answer by
Employee

Hi Alistair,

You can do so by using queryDef API on the temporary schema created for Enrichment activity. Please follow the steps outlined below from the test I carried out. You can make changes as per your workflow.

  1. In my setup there is a query activity, followed by enrichment which is followed by JS code activity that will populate the instance variable with relevant data from Enrichment.
  2. Referring to attached screenshot, inside the enrichment I've generated a modified first name of recipient by appending the string " is my first name" to the existing recipient first name. So, John will be modified to "John is my first name" and will be tagged as newFirstName field. 
  3. Please see that the alias has been modified inside Enrichment output columns and the new field is called @newFirstName.
  4. Also referring to schema of enrichment the temporary table can be referenced using schema temp:enrich.
  5. Inside JS code activity, perform a queryDef call on this temp schema and then read from the relevant column.

Adding the code here for reference.

var query = xtk.queryDef.create( <queryDef schema="temp:enrich" operation="select"> <select> <node expr="@newFirstName"/> </select> </queryDef>); var resultSet = query.ExecuteQuery(); for each (var row in resultSet) { logInfo("From temp schema : " + row.@newFirstName); instance.vars.AKTEST = row.@newFirstName; logInfo("From instance variable : " + instance.vars.AKTEST); }

When my sample workflow is executed, the output is 

Hope this helps.

Regards,

Vipul

Avatar

Level 3

That works perfectly.

Doing this I am able to populate my extract file name with this variable and am also able to pass it through to my template subject line from my delivery by using 'delivery.label = instance.vars.AKTEST' in the delivery modification script and then using <%= message.delivery.label %> in the subject line in the template.

Thank you so much for your help!

Avatar

Employee

Hi,

COuld you please let me know how to pass delivery label in the subject line?

<%= message.delivery.label %> in the subject line in the template- not working for me and passing exactly the same text in the subject line.

'delivery.label = instance.vars.AKTEST' in the delivery modification script---This worked for me.

Avatar

Level 1
But there is no js activity in Adobe Standard, how do you update a variable in Standard version