Solved

Merging two queries for double-dynamic mail merge

Posted on 2006-07-18
3
208 Views
Last Modified: 2013-12-24
Using CFDOCUMENT, I'm trying to creating a PDF thank-you letter to donors.  Simply inserting the donor data into a message created within the CFDOCUMENT is no problem, but I'm trying to allow the client to modify the template dynamically as well.  So basically we need to output the dynamic letter, and within the letter, output the dynamic donor data based on a URL.sort.

I've tried inserting #queryname.field# in the text of the dynamic letter (inside cfoutputs, of course), but the final PDF renders with the pound signs and not with the dynamic donor data.

Here is the CFDOCUMENT page I've been working with.  Both queries work perfectly on their own.  Any thoughts?  Thanks!

<cfif isDefined("URL.sort")>
<cfparam name="URL.sort" default="1">
<cfquery datasource="#dsn#" name="qGetDonor">
      SELECT *
      FROM donors
      WHERE intTransID = #URL.sort#
</cfquery>
</cfif>

<cfquery datasource="#dsn#" name="qGetLetter">
      SELECT lettermessage
      FROM donorinfo
      WHERE ID = 1
</cfquery>

<cfdocument format="pdf">
<cfoutput>
#qGetLetter.lettermessage#
</cfoutput>
</cfdocument>
0
Comment
Question by:ondeckstudio
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
g127404 earned 250 total points
Comment Utility
I can think of 2 ways and neither are that great...

1. Restructure your letter so you can insert the name at the right point with more lettermessages[index] or just put:
Dear, #qGetDonor#
#qGetLetter.lettermessage#
Thanks,
Us

2. Turn your query into a string, parse it out, do a find for the field you're looking for, insert your variable then output the corrected string.

Be interested to see what other suggestions come up.
0
 

Author Comment

by:ondeckstudio
Comment Utility
Those were the two options we'd considered as well, but were hoping for something more direct.

However we did implement the second idea and it has worked perfectly, so it's what we're sticking with.  The code is copied down below:

<cfset stringtoreplace = qGetLetter.lettermessage>
<cfset find = "">
<cfset replace = "">

<cfset find = ListAppend(find, "InsertFirstName,InsertPaymentAmount,Insertdonorcity")>
<cfset replace = ListAppend(replace, qGetDonor.donorFirstName)>
<cfset replace = ListAppend(replace, DollarFormat(qGetDonor.paymentAmount))>
<cfset replace = ListAppend(replace, qGetDonor.donorCity)>

<cfoutput>
#Replacelist(stringtoreplace, find, replace)#
</cfoutput>
0
 
LVL 4

Expert Comment

by:g127404
Comment Utility
Thanks for the points, as well as posting the code you're using.  That solution you're using is simple and works so stick with it. =-)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now