Hello all,I am stuck in a requirement where i have to calculate sum of one column in adobe campaign classic ,please suggest how can i get below result as output-specifically last line in display logs after executing query or enrichment activity
Classification | Total Recipient | Total Contract | Diff |
6 | 100 | 50 | 50 |
1 | 500 | 50 | 450 |
3 | 800 | 100 | 700 |
9 | 600 | 200 | 400 |
4 | 900 | 500 | 400 |
Total | 1900 | 900 |
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @Shruti1 ,
You can use the following code after your enrichment activity inside a JavaScript activity. Ensure that all the necessary fields are created and have alias names, so you can reference these alias names in the query. Make sure to adjust the field names in the code to match the actual field names in your schema or enrichment.
// Define the schema name from the target schema
var schemaName = vars.targetSchema.substr(vars.targetSchema.indexOf(":") + 1);
// Create the query definition to select required fields
var query = xtk.queryDef.create(
<queryDef schema={vars.targetSchema} operation="select">
<select>
<node expr="@totalRecipient"/>
<node expr="@totalContract"/>
<node expr="@classification"/>
</select>
</queryDef>
);
// Execute the query
var result = query.ExecuteQuery();
// Initialize variables to store the sums
var totalRecipient = 0;
var totalContract = 0;
var totalDiff = 0;
// Loop through each record in the result set
for each (var rcp in result.recipient) {
// Sum TotalRecipient and TotalContract
totalRecipient += rcp.TotalRecipient;
totalContract += rcp.TotalContract;
// Calculate the difference and sum it
totalDiff += rcp.TotalRecipient - rcp.TotalContract;
}
// Log the calculated totals
logInfo("Total Recipient Sum: " + totalRecipient);
logInfo("Total Contract Sum: " + totalContract);
logInfo("Total Diff Sum: " + totalDiff);
Thanks
Views
Replies
Total Likes
Hi @Shruti1 ,
You can use the following code after your enrichment activity inside a JavaScript activity. Ensure that all the necessary fields are created and have alias names, so you can reference these alias names in the query. Make sure to adjust the field names in the code to match the actual field names in your schema or enrichment.
// Define the schema name from the target schema
var schemaName = vars.targetSchema.substr(vars.targetSchema.indexOf(":") + 1);
// Create the query definition to select required fields
var query = xtk.queryDef.create(
<queryDef schema={vars.targetSchema} operation="select">
<select>
<node expr="@totalRecipient"/>
<node expr="@totalContract"/>
<node expr="@classification"/>
</select>
</queryDef>
);
// Execute the query
var result = query.ExecuteQuery();
// Initialize variables to store the sums
var totalRecipient = 0;
var totalContract = 0;
var totalDiff = 0;
// Loop through each record in the result set
for each (var rcp in result.recipient) {
// Sum TotalRecipient and TotalContract
totalRecipient += rcp.TotalRecipient;
totalContract += rcp.TotalContract;
// Calculate the difference and sum it
totalDiff += rcp.TotalRecipient - rcp.TotalContract;
}
// Log the calculated totals
logInfo("Total Recipient Sum: " + totalRecipient);
logInfo("Total Contract Sum: " + totalContract);
logInfo("Total Diff Sum: " + totalDiff);
Thanks
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies