Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling cfoutput within cfscript

Tags:

coldfusion

I'm using a cftry catch to send an email to our alerts box when a widget on our site fails to load.

the cfcatch.message and cfcatch.detail don't provide enough detail on which page in particular is failing.

We have an attribute r_page which returns the page id when output.

However the email is generated using CFScript. How do i call <cfoutput>"#r_page#"</cfoutput> within my script to display in the email body?

<cfscript>
        mailObj = new mail();
        mailObj.setFrom(application.errorEmail);
        mailObj.setTo(application.errorEmail);
        mailObj.setSubject("THIS IS THE SUBJECT");
        mailObj.setBody("A page is broken. Details: " & cfcatch.detail & " Message: "& cfcatch.message);
        mailObj.send();
</cfscript>

Thanks

like image 401
Hoggie1790 Avatar asked May 10 '26 20:05

Hoggie1790


1 Answers

If you don't quote it, it will be evaluated automatically in the setBody() method, just like your current cfcatch members are being evaluated.

<cfscript>
    mailObj = new mail();
    mailObj.setFrom(application.errorEmail);
    mailObj.setTo(application.errorEmail);
    mailObj.setSubject("THIS IS THE SUBJECT");
    mailObj.setBody("A page is broken. - " & r_page & " Details: " & cfcatch.detail & " Message: "& cfcatch.message);
    mailObj.send();
</cfscript>

You can also evaluate it inline too using ##.

<cfscript>
    mailObj = new mail();
    mailObj.setFrom(application.errorEmail);
    mailObj.setTo(application.errorEmail);
    mailObj.setSubject("THIS IS THE SUBJECT");
    mailObj.setBody("A page is broken. - #r_page# Details: " & cfcatch.detail & " Message: "& cfcatch.message);
    mailObj.send();
</cfscript>
like image 152
Busches Avatar answered May 12 '26 12:05

Busches



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!