I have a query which returns multiple results with just data in one column as different for a particular report number. I want to group the results for one report number and send an email to one person for all the action items. Below is my query
<cfquery name="qryCorrectiveDueDate" datasource="#application.config.DSN#">
SELECT FR.report_id,
FR.report_number,
IR.investigation_id,
CA.action_who,
CA.action_who_email,
CA.action_what,
CA.action_when,
CA.action_type,
CA.action_complete_date
FROM xyz_gir.dbo.xyz_flash_report AS FR,
xyz_gir.dbo.xyz_investigation_report AS IR,
xyz_gir.dbo.xyz_corrective_actions AS CA
WHERE FR.report_id = IR.report_id
AND IR.investigation_id = CA.investigation_id
AND DATEDIFF(day,CA.action_when,GETDATE()) > 1
AND CA.action_complete_date IS NULL
ORDER BY IR.investigation_id
</cfquery>
The Result Set looks something like this:
report_id report_number investigation_id action_who action_who_email action_what action_when action_type action_complete_date
2 13-0002 2 Hans-Joerg Wolf hans-joerg.wolf#xyz.com Action 1 00:00.0 Repair NULL
4 13-0004 3 Robert Michael robert.michael#xyz.com fghfgh 00:00.0 Repair NULL
5 13-0005 4 Masoud Aghel Masoud.Aghel#xyz.com sdfsdfsdf 00:00.0 Repair NULL
5 13-0005 4 Masoud Aghel Masoud.Aghel#xyz.com hhjghj 00:00.0 Repair NULL
What i want to do is send one email to the action_who_email value for multiple lines with the same investigation id. If i use cfoutput group attribute this is the output:
hans-joerg.wolf#xyz.com
Report ID: 2
Report Number: 13-0002
investigation id: 2
Action Who :Hans-Joerg Wolf
Action What: Action 1
Action When: 2013-04-26 00:00:00.0
Action type:Repair
Action Complete Date:
robert.michael#xyz.com
Report ID: 4
Report Number: 13-0004
investigation id: 3
Action Who :Robert Michael
Action What: fghfgh
Action When: 2013-05-05 00:00:00.0
Action type:Repair
Action Complete Date:
Masoud.Aghel#xyz.com
Report ID: 5
Report Number: 13-0005
investigation id: 4
Action Who :Masoud Aghel
Action What: sdfsdfsdf
Action When: 2013-04-29 00:00:00.0
Action type:Repair
Action Complete Date:
Report ID: 5
Report Number: 13-0005
investigation id: 4
Action Who :Masoud Aghel
Action What: hhjghj
Action When: 2013-04-29 00:00:00.0
Action type:Repair
Action Complete Date:
And This is my cfoutput:
<cfoutput query="qryCorrectiveDueDate" group="investigation_id">
<b>#action_who_email#</b><br>
<cfoutput>
Report ID: #report_id#</br>
Report Number: #report_number#</br>
investigation id: #investigation_id#</br>
Action Who :#action_who#</br>
Action What: #action_what#</br>
Action When: #action_when#</br>
Action type:#action_type#</br>
Action Complete Date: #action_complete_date#</br></br>
</cfoutput></br>
</cfoutput>
But if i do the same thing with cfmail on the query and group it, that throws a javax.mail.MessagingException: Could not connect to SMTP host: 127.0.0.1, port: 25; error.
My CFMAIL code is as below
<cfmail query="qryCorrectiveDueDate" from="EHS#jdsu.com" to="#action_who_email#" group="#investigation_id#" subject="xyz">
<p>#action_who#,</p>
<p>Due Dates for Corrective Actions for the Incident #report_number# have lapsed </p>
<p>You are receiving this notification, as the Manager/Supervisor to implement the Corrective Actions </p>
<p>Incident No: #report_number# </p>
<p>Corrective Action: #action_what#</p>
<p>Due Date: #action_when#</p>
</cfmail>
Please note that i am running Coldfusion locally with xampp, and although the mails dont get delivered, i can see them in the undelivered folder in coldfusion. The same file has other cfmail tags which do not throw the connection exception if this cfmail tag is commented out.
I apologize if my question is very generic, but i either have to do this with coldfusion or i might have to write a function to treat my result set as a temp table. Its easier with coldfusion i believe, if i know how to make this work.
I believe your actual problem is that you're using pound signs in the group attribute.
group="#investigation_id#" should be group="investigation_id"
--Edit--
This below answer is moot as the OP was misleading.
I think this is because you do not need cfoutput tags inside the cfmail tag. It's odd that it causes a mail error, though.
anyway...
I would try using cfsavecontent then output the variable in the cfmail.
<cfsavecontent variable = "mailBody">
<cfoutput query="qryCorrectiveDueDate" group="investigation_id">
<b>#action_who_email#</b><br>
<cfoutput>
Report ID: #report_id#</br>
Report Number: #report_number#</br>
investigation id: #investigation_id#</br>
Action Who :#action_who#</br>
Action What: #action_what#</br>
Action When: #action_when#</br>
Action type:#action_type#</br>
Action Complete Date: #action_complete_date#</br></br>
</cfoutput>
</br>
</cfoutput>
</cfsavecontent>
<cfmail ...>
#mailBody#
</cfmail>
Now that you've removed the hash tags, your issue is likely a missing cfoutput tag in the email. Similar to the group attribute of the cfoutput tag, you need another cfoutput tag to loop through the grouped records.
Tested on CF8 locally.
<cfmail query="q" group="field">
<cfoutput>
#field# - #field2#
</cfoutput>
</cfmail>
Related
I've write a functionality about send email process. Here I've set Mail Server details admin setting. And write a below code for sending email. I can successfully send & receive email to my gmail account. But Here I've added some paragraph with anchor tag value that is click me.
<cfoutput>
<cfmail from="test#gmail.com" to="test#gmail.com" username="myemail#gmail.com" password="mypass" port="587" subject="Chaange title" >
<p> I'm from test link click Me 2! </p>
</cfmail>
</cfoutput>
The issue is in my email not received as a click me as a link. Instead it will display entire html about anchor tag. FYR please refer my email content image.
Note : I've already tried with cfsavecontent too but it's not help me.
Could you any one help on this. Why it's was happen ? Thanks in advance.
Add type="html" to your cfmail tag. That should indicate to the end user's email client that the message should be displayed as an HTML page instead of just plain text.
Below is a field on my forms.py:
body = forms.CharField(label='Paste Email Thread Here',
widget=forms.Textarea(attrs={
"class": "body-QAerror",}))
And this is the data that I have entered:
Which I passed onto my html template; however, it didn't retain the email format (with indentions) See below:
From: Firstname, Lastname Sent: Wednesday, February 27, 2019 11:01 AM To: someonelese#example.com Subject: server is unresponsive Importance: High For some unknown reason, the server is not responsive – can’t log in, and affected all end users. I filed a ticket 123456. Please communicate this if some users are asking for the issue. Thanks, Firstname MiddleName 78456431 FM#example.com
Is it possible to still retain the email format?
HTML ignores whitespace. You'll need to convert those newlines to HTML tags.
There are built-in Django template filters to do this: linebreaks and linebreaksbr.
So you would do for example:
{{ email.body|linebreaks }}
I have a button (anchor tag) that send a confirm message if you press it.
The problem is that for example if you press it 5 times very quickly it will send 5 confirm messages, if you press it 2 times it will send 2 messages.
This can occur when the user has low connection speed and while the page is refreshing he presses again the button.
How can I manage this situation? I though of disabling the button but for other reasons this is not possible.
<a class="msg" href="/manage/conversations.cfm?destination=#destination#">
#ucase(request.l('Send'))#
</a>
Thank you for your time
Ultimately, you need to have code on your server to prevent processing the link multiple times from the same user.
However, to solve the UI issue, have you link call a function instead of the cf file directly.
<a class="msg" href="javascript: processLink(#destination#);">
#ucase(request.l('Send'))#
</a>
<script>
runCount = 0;
function processLink(destination){
runCount++;
if (runCount == 1){
window.location.href = "/manage/conversations.cfm?destination=" + destination;
}
}
</script>
As mentioned in the previous answer it's nice to have some client side javascript to stop duplicate submissions from trigger happy users however you should also do this checking server side.
One approach would be to create a hidden formfield with a GUID that coldfusion generates when coldfusion renders your form.
So something like:
<cfset GUID = createUUID()>
<cfoutput>
<form id="frm" action="/target.cfm" method="post">
<input type="hidden" name="guid" value="#GUID#">
<!-- all your formfields go here -->
<input type="submit">
</form>
</cfoutput>
On the server side the target page then checks if it has already previously received the GUID. There are lots of ways to do, here are two of many ways.
a) Use Session Scope.
This is probably the quickest way if you are not running in a clustered environment and just need something quick for a tiny application.
<cfif isDefined("session.MYPAGE_GUID") AND session.MYPAGE_GUID EQ form.guid>
<cfoutput>Duplicate Form Submission</cfoutput>
<cfabort>
<cfelse>
<cfset session.MYPAGE_GUID = form.guid>
<!-- Do Business Logic Here -->
</cfif>
b) Use a Database Table.
Create a database table with a column called GUID. Make sure that GUID is the primary key or has a unique constraint.
Before you run your business logic insert the form.GUID into the database table. If you can do the insert process your business logic, if not the database query will throw an error that the record exists. You can then catch this error and take the appropriate action for a duplicate submission.
I prefer the database option as it works across clustered environments and database server are solid protecting against race conditions to ensure that a GUID is only set once.
Please be aware that this is just demonstrating the basic concepts and is not a drop in solution. There is a bit of more work to get these concepts into an e-commerce solution.
The best way is to disable the link once it's selected. If you don't want to do that, an alternative is to structure conversations.cfm like this.
<div id="pageContent">
small amount of text
</div>
<cfflush>
</body>
</html>
<cfsavecontent variable = "actualPageContent">
code
</cfsavecontent>
<cfoutput>
<script>
var #toScript(actualPageContent, "newPageContent")#;
document.getElementById("pageContent").innerHTML = "newPageContent";
</script>
</cfoutput>
We have a form which has some mandatory fields and 2 buttons(One is Submit, second is Search).
Search buttton code is like :
<input name="btnSearch" type="submit" id="Search" value="Search">
This code redirects to action form and then further to a new screen. Finally it reverts back to the main form and has code to restore the selected values.
One of the mandatory fields has the following code:
<td align="right">Class Id:<font color="red">*</font></td>
<td><cfselect name="YY_CLASS_ID" size="1" query="XX_Class_List"
value="XX_CLASS_ID" display="XX_DESCRIPTION"
required="yes"selected="#variables.XX_CLASS_ID#">
<cfif variables.XX_CLASS_ID eq "">
<option value="" selected></option>
</cfif>
</cfselect></td>
When user clicks on the search button and this Class ID dropdown is blank, they get an error that "Error in YY_CLASS_ID text".
yy_class_id field has required attribute as ‘yes’ and message attribute is not set. As per our understanding, this means error should always come if the user tries to navigate away from the screen without populating the CLASS ID.
However, as per our user ,they were not getting this error in CF9 and started coming after the CF10 upgrade. They are frequent users of the screen and could have not missed this in past if this was happening during CF9 days.
Can anyone please confirm if something has changed in CF10 which was not earlier in CF9 and causing this issue. Or we missing something here.
Let me know if any more information is needed.
My page creates a few random variables to pick prizes and winners for a drawing, and I want to write the prize winners and their prizes to a table after the winner clicks a button to claim the prize.
The problem is I want them to stay on the page so that a prize can be picked again if it isn't claimed.
The best solution I can come up with is an action page that the cfinput button references, but I don't want the action page to open up, I just want the cfquery on that page to run behind the scenes.
Here's an example of my query:
<cfquery name="updateQuantity" datasource="christmas">
UPDATE PRIZES
SET QUANTITY = QUANTITY - 1
WHERE prize_ID = #prizeID#
</cfquery>
I tried making my button a "submit" button and using cfif isDefined("form.Submit") to run the cfquery on the same page, but the submit button refreshes the page (which I don't want) and writes the next picked winner instead of the prizeID of the current session:
<cfform>
<cfinput name="submit" type="submit" value="Claim Your Prize!" onClick="">
</cfform>
<cfif isDefined("form.Submit")>
<cfquery name="updateQuantity" datasource="christmas">
UPDATE PRIZES
SET QUANTITY = QUANTITY - 1
WHERE prize_ID = #prizeID# </cfquery>
</cfif>
prizeID is determined by the randomly selected prize.
Adam is correct.
While AJAX is what you're after, ColdFusion's AJAX related tags are not the way to go.
Take the time to learn JQuery and AJAX (it isn't too hard, and the CF community has some great examples and guides) and do it properly; with your example requirements, you should be up and running in no time.
That way you can properly manage any logging and error handling that you may need to as well. Good luck!
It sounds like ColdFusion.Ajax.submitForm would work for you.
In general, I think an AJAX request is what you are looking for.