How to attack this

Is there anything you guys didn’t think of? so much to blog about when I get done with this project!

Thank You
Dan Vega
danvega@gmail.com
http://www.danvega.org/

Lol, thanks Dan!

I just finished using this functionality myself on the ContentBox email templates so it was fresh in my mind :slight_smile:

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

I just tried this approach and I am having an issue. When I initialize my application with the following code in my interceptor I get an error. Inside of the args struct I am trying to grab the payment method but it errors right away and says order is not defined. Of course its not yet because it hasn’t been passed yet, why is this happening?

public void function onPlaceOrder(event,interceptData){
var order = arguments.interceptData.order;
var user = order.getUser();
var creditCard = order.getCreditCard();
var subject = “Client Portal - New Order Placed”;

var bodyTokens = {
firstName = user.getFirstName(),
lastname = user.getLastName(),
paymentMethod = order.getPaymentMethod(),
amount = dollarFormat(order.getTotalCost()),
cc_name = isNull(creditcard) ? ‘’ : creditCard.getName(),
cc_type = isNull(creditcard) ? ‘’ : creditCard.getType(),
cc_account = isNull(creditcard) ? ‘’ : creditCard.getAccountDisplay(),
cc_expdate = isNull(creditcard) ? ‘’ : creditCard.getExpMonth() & “/” & order.getCreditCard().getExpYear(),
cc_cvv = isNull(creditcard) ? ‘’ : creditCard.getCVV()
};

var mail = mailservice.newMail(to=variables.admins,
from=variables.outgoingemail,
subject=subject,
bodyTokens=bodyTokens);

// generate content for email from template
mail.setBody( renderer.renderView(view=“email_templates/order_new_admin”,args={paymentMethod=order.getPaymentMethod()}) );
mail.setType(“HTML”);
mail.setUseSSL(true);
mail.setUseTLS(true);
mailService.send( mail );
}

not sure, try to add some log statements and see what is going on.

Every interceptor has a ‘log’ object already

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

I am not sure what to do here, nothing is getting logged. The variable order is there fine when the interceptor runs but for whatever reason during starting its trying to inject those arguments into the view and its just not there yet…

public void function onPlaceOrder(event,interceptData){
var order = arguments.interceptData.order;
var user = order.getUser();

var bodyTokens = {
firstName = user.getFirstName(),
lastname = user.getLastName()
};

var mail = mailservice.newMail(to=variables.admins,
from=variables.outgoingemail,
subject=subject,
bodyTokens=bodyTokens);

log.error("payment method: " & order.getPaymentMethod());

// generate content for email from template
mail.setBody( renderer.renderView(view=“email_templates/order_new_admin”,args={foo=order.getPaymentMethod()}) );
mail.setType(“HTML”);
mail.setUseSSL(true);
mail.setUseTLS(true);
mailService.send( mail );
}

# Variable ORDER is undefined.
**mail.setBody( renderer.renderView(view="email_templates/order_new_admin",args={foo=order.getPaymentMethod()}) );** 

Dan, is this a fully patched ColdFusion server?

If it is on the line you are saying it is on

**mail.setBody( renderer.renderView(view="email_templates/order_new_admin",args={foo=order.getPaymentMethod()}) );** 

Then as one who as and does keep falling for this, you may wish to make sure your ColdFusion server is indeed 9.01.

Yes, running 9.0.1

Oh well there goes that thought then :frowning:

Agh good observation. I would try to set an args outside and then pass it. I have found cf 9 sucks at variable resolution for implicit literal expressions.

Try to build the args structure first and then pass it in.

Everything works fine until I try to add arguments to the view… It’s almost like its trying to preload these into the view, if it were I could understand this error.

Did you try building the structure outside of any method calls? I ran into the same issues

That was it! I created the view arguments outside and passed in the structure and it worked fine. Thanks guys!

Yea this needs to be submitted to adobe as a crappy bug.

Could I bug you for the syntax you used to create the struct and pass
it in? I think I've been fighting with the same bug for a good day
now.
I've tried various ways of creating the struct, but none of them make
it past the error:

"Element ARGSSTRUCT is undefined in LOCAL"

Shouldn't this work?

local.argsStruct = StructNew();
local.argsStruct.name = "Molly";
#renderView(view=arguments.view,args=local.argsStruct)#

I've apparently been having one of those days. I should have gone and
had a nap before posting for help. If you're going to write cfscript
variable assignment, then it really helps if you put cfscript tags
around it.

For reference on the original problem with the args needing to be a
struct rather than inline evaluated - we have a couple of different
CF9 servers. One of them runs the inline params fine, the other
chokes on it, and needs the struct built in advance and passed in.
Both are running CF 9.

ColdFusion Server Standard 9,0,1,274733 - have to build the args
struct first.
ColdFusion Server Standard 9,0,0,251028 - args structure works fine
with inline evaluation.

it should

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano