exports.handler = function (context, callback) {
console.log('this is the test for changing the email content dynamically');
// scenario: add custom content to order changed email
var model = context.items.getModel;
var user = context.items.getUser;
var firstName = user.firstName;
console.log('user first name is ' + firstName);
console.log('order number is ' + model.orderNumber);
console.log('email subject is ' + context.items.getSubject);
var subject = context.items.getSubject;
if (subject == "order.changed") {
model.customContent = "This is custom content added dynamically through arc for user " + firstName + " for order " + model.orderNumber;
context.exec.setModel(model);
var newContent = context.items.getModel;
console.log('new content is ' + JSON.stringify(newContent, null, 2));
console.log('set new content successfully');
}
callback();
};