Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How pass an object as a parameter to a content block?

israel_sanchez
Level 2
Level 2

Hello all, I have a workflow with a Java Script task that queries and retrieves a set of products from a custom schema, those products are selected based on specific properties for each recipient, so I have a custom content block with the HTML template where the products info will be filled, the question is, how can I pass those objects from the JS task to the content block?

 

I would like to say the complete email body is build in AEM.

Topics

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

1 Accepted Solution
isahore
Correct answer by
Level 3
Level 3

Hi @israel_sanchez,

I assume every recipient will be getting a different set of products. In your JS code, you can add those products into the temporary schema against each recipient record using the xtk.session.Write() method [I know it is not efficient to this method to write into temporary tables], and then get all the products in the content block just like other targetData elements and attributes.

e.g. <%= targetData.product1 %>

 

To make the workflow efficient, you can avoid writing into the temporary schema, but write into a file (.csv) on the server instead. The file would contain the recipient identifier, and the products per line of data. Later on in the workflow, you can use the "data loading (File)" activity to read that file and then enrich your targeting dimension with the data from that file.

You can keep using the same file name for every execution of the workflow, but remember to delete the file from the server once it has served its purpose (end of the workflow). This operation (file write/read) is way faster than writing into the temporary schema in your JS code when the number of records in the temporary schema is too high.

 

Let me know if that helps.

 

Thanks,

Ishan

View solution in original post

6 Replies
DavidKangni
Community Advisor
Community Advisor

Hi there,

Assuming you want to use last name under recipient schema.

 

If your block is a JS recipient.lastName

If your block is html then <%= recipient.lastName %>

 

Basically make sure you can read you calculated data from the workflow.

 

Thanks,

David

isahore
Correct answer by
Level 3
Level 3

Hi @israel_sanchez,

I assume every recipient will be getting a different set of products. In your JS code, you can add those products into the temporary schema against each recipient record using the xtk.session.Write() method [I know it is not efficient to this method to write into temporary tables], and then get all the products in the content block just like other targetData elements and attributes.

e.g. <%= targetData.product1 %>

 

To make the workflow efficient, you can avoid writing into the temporary schema, but write into a file (.csv) on the server instead. The file would contain the recipient identifier, and the products per line of data. Later on in the workflow, you can use the "data loading (File)" activity to read that file and then enrich your targeting dimension with the data from that file.

You can keep using the same file name for every execution of the workflow, but remember to delete the file from the server once it has served its purpose (end of the workflow). This operation (file write/read) is way faster than writing into the temporary schema in your JS code when the number of records in the temporary schema is too high.

 

Let me know if that helps.

 

Thanks,

Ishan

View solution in original post

israel_sanchez
Level 2
Level 2
Thank you, I'll check that way, I think to query inside the Content Block is a good approach, I'll keep you posted once we have the WF completed.
Sukrity_Wadhwa
Employee
Employee
Hi @israel_sanchez, Were you able to resolve this query with the given solution? Do let us know. Thanks!
israel_sanchez
Level 2
Level 2
That works perfectly, all objects from Enrichment activity are stored in "targetData" object