Highlighted

passing a date variable inside of a function of a CFC

New Here ,
Sep 23, 2015

Copy link to clipboard

Copied

I'm using CF 9 on windows 8 64bit

This is probably a simple solution. I have a form that will list all of the members of our church club from a given date that is selected from a form field. After the date is selected I will press my submit button and I expect to see the date listed with all of the members that were in the class listed as well. However I am experiencing an error when the page generates. This error reads

“The value returned from the meedate function is not of type date.”

How can I pass a date variable into my CFC so that it will pass through correctly and display my desired results. Below is the code of my CFC that I am calling as well as the Coding for the page that should display the desired results. The particular function that I am referring to is entitled "brother" of the component called “brother”, and the error code throw when it encounters the variable called '#meetingdate#'. Please let me know if If I am missing something. Thanks in advance for your help.

<!--- my CFC coding--->

<cfcomponent displayname="brother" hint="collect all names from brother">

     <cffunction name="meedate" hint="convert meeting date into a format that Mysql can understand" output="yes" access="public" returntype="date">

          <cfset prestartdate = form.squweekbegin>

          <cfset meetingdate = LSDateFormat(prestartdate, 'yyyy-mm-dd')>

          <cfset prestartdate2 = form.squweekbegin>

          <cfset meetingdate2 = LSDateFormat(prestartdate, 'yyyy-mm-dd')>

          <cfreturn meedate>

     </cffunction>

     <cffunction name="sfois_verify" hint="Verify that SFOID is activated in this session" output="yes" access="public" returntype="query">

               <cfquery name="sfois_verify"datasource="master">

                    SELECT sfois FROM name

               </cfquery>

          <cfreturn sfois_verify>

     </cffunction>

      <cffunction name="scapt_verify" hint="Verify that CAPT is activated in this session" output="yes" access="public" returntype="query">

          <cfquery name="scapt_verify"datasource="master">

          SELECT scapt FROM name

               </cfquery>

          <cfreturn scapt_verify>

     </cffunction>

     <cffunction name="brother" hint="0" output="yes" access="public" returntype="query">

          <cfquery name="brother" datasource="master">

                select name.foiid, meeid, meenotes, CONCAT(name.fname,' ',name.xholy) AS brother, CONCAT(name.fname) AS brothershort, CONCAT(name.fname,' ',name.xholy,' ',name.slave) AS brother3, type, meesquadlt, ltid

from name, meeting, squadlt

where not exists

(select 1

from meeting

where meefoiid = name.foiid

and meedate = '#meetingdate#'

/*and squactive = 1*/

)

AND CITY = 'richmond'

AND STATUS = 'A'

group by brother

order by type, brother

</cfquery>

<cfreturn brother>

</cffunction>

</cfcomponent>

<!--- my page displaying the results--->

<cfcookie name="constantdate" value="#form.squweekbegin#">

<cfinvoke component = "Componet.insertintoname"

method = "sfois_verify"

returnVariable = "sfois_verify">

<cfinvoke component = "Componet.insertintoname"

method = "scapt_verify"

returnVariable = "scapt_verify">

<cfinvoke component = "Componet.insertintoname"

method = "meedate"

argumentcollection="datefromformfield"

returnVariable = "meedate">

<!---is the session is HH--->

<cfif #session.user_id# EQ "#sfois_verify.sfois#" or #session.user_id# EQ "#scapt_verify.scapt#">

<cfinvoke component = "Componet.insertintoname"

method = "brother"

returnVariable = "brother">

<cfquery name="Present" datasource="master">

SELECT trim(CONCAT(name.fname,' ',name.xholy,' (',name.slave,')')) AS brother, trim(CONCAT(name.fname,' ',name.xholy)) AS brother2, trim(concat(name.fname,' ',name.slave)) AS slavename, meeid, meenotes, sfois, scapt, meeguest, meedate FROM name LEFT JOIN meeting ON meefoiid = foiid WHERE <!---<cfif #session.user_id# EQ "#sfois_verify.sfois#"> sfois = '#session.user_id#'<cfelseif #session.user_id# EQ "#scapt_verify.scapt#">scapt = '#session.user_id#' </cfif>AND --->meedate = '#meetingdate#' AND city = 'richmond' group by meefoiid order by brother

</cfquery>

<!---is the session is not HH--->

<cfelse>

<cfquery name="brother" datasource="master">

select name.foiid, meeid, CONCAT(name.fname,' ',name.xholy) AS brother, CONCAT(name.fname) AS brothershort, type, meesquadlt, ltid

from name, meeting, squadlt

where not exists

(select 1

from meeting

where meefoiid = name.foiid

and meedate = '#meetingdate#'

/*and squactive = 1*/

)

AND type = 'foi'

AND squadlt = '#session.user_id#'

AND CITY = 'richmond'

AND STATUS <> 'd'

AND STATUS <> 'T'

AND STATUS <> 'I'

AND Form4Complete <> 'no'

<!---AND Form4Complete = 'N/A'--->

group by brother

order by brother

</cfquery>

<cfquery name="Present" datasource="master">

SELECT trim(concat(name.fname,' ',name.xholy)) AS Brother, meeid, meenotes, meedate, meeguest FROM name LEFT JOIN meeting ON meefoiid = foiid WHERE squadlt = '#session.user_id#' AND meedate = '#meetingdate#' AND type = 'foi' AND city = 'richmond' group by meefoiid order by brother

</cfquery></cfif>

<cfcache action="ClientCache" timespan="#createTimeSpan(0,0,10,0)#">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">

$(document).ready(function() {

$('input:meenotes').focus(

function(){

$(this).val('');

});

$('input:meeguest').focus(

function(){

$(this).val('');

});

});

</script>

<meta name="viewport" content="width=device-width" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<style type="text/css">

@import url("SR_CSS/Attendance_css.css");

@import url("SR_CSS/media_queries.css");

@import url("SR_CSS/media_queries_ipad_portrait.css");

</style>

</head>

<body>

<div id="present">

<cfif #form.squweekbegin# NEQ "#present.meedate#"><div id="text_white_attendance">

List Is Empty For <br><br><cfoutput>#LSDateFormat(meetingdate,'DDD MMM. DD, YYYY')#</cfoutput>

<!---Content for id "text_white" Goes Here---></div>

<cfelse>

<div id="text_white_attendance">

<cfoutput>#LSDateFormat(meetingdate,'DDD MMM. DD, YYYY')#</cfoutput>

<!---Content for id "text_white" Goes Here---></div>

</cfif><!---Content for id "present" Goes Here---></div>

<cfoutput query="present">

<div id="div_present">

<a href="edit_insert_attendance1.cfm?meeid=#meeid#"><span class="div_present_current_row">#currentrow#).</span></a><a href="edit_insert_attendance1.cfm?meeid=#meeid#"> #Present.Brother#<cfif #present.meenotes# eq""><cfelseif #present.meenotes# NEQ""> - <span class="note_indicator">N</span></cfif>

<cfif #present.meeguest# eq"" or #present.meeguest# eq "0"><cfelseif #present.meeguest# NEQ""> - <span class="guest_indicator">#present.meeguest#</span></cfif></a><br /><!---Content for id "div_present" Goes Here---></div></cfoutput>

<br />

<br />

<div id="back_home_link"><a href="Home.cfm">Back to Home Page</a></div>

<br />

<br />

<form action="insert_attendance2.cfm" name="form" method="post" enctype="application/x-www-form-urlencoded">

<input type="hidden" value="<cfoutput>#meetingdate#</cfoutput>" name="meedate">

<input type="hidden" value="<cfoutput>#form.squweekbegin#</cfoutput>" name="squweekbegin">

<div id="Container_attendance">

<cfoutput query="brother">

<div id="header_name"><!---#currentrow#---> #brother.brother#<cfif #brother.type# eq"proc"> (Proc.)<cfelseif #brother.type# eq "jrfoi"> (Jr. FOI)<cfelseif #brother.type# eq"GV"> (Guest)</cfif></div>

<div id="div_radio">

<input type="radio" class="class_radio" name="meefoiid" value="#brother.foiid#" required="required">

</div><div id="div_notes"><textarea rows="5" name="meenotes" class="meenotes" placeholder="Notes on Bro. #brother.brothershort#" maxlength="255" cols="25">

</textarea></div>

<div id="div_guest"><input type="text" pattern="[0-9]*" max="3" class="class_guest" placeholder="guest" size="4" name="meeguest" value="" /></div>

<div id="div_submit"><input name="Add to attendance" class="submit_button_attendance" type="submit" value="Add - #brother.brothershort# #LSDateFormat(meetingdate,'MM/DD/YY')#" /></div></cfoutput>

<!---Content for id "attendance_container" Goes Here---></div>

</form>

<!------>

</body>

</html>

Views

505

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

passing a date variable inside of a function of a CFC

New Here ,
Sep 23, 2015

Copy link to clipboard

Copied

I'm using CF 9 on windows 8 64bit

This is probably a simple solution. I have a form that will list all of the members of our church club from a given date that is selected from a form field. After the date is selected I will press my submit button and I expect to see the date listed with all of the members that were in the class listed as well. However I am experiencing an error when the page generates. This error reads

“The value returned from the meedate function is not of type date.”

How can I pass a date variable into my CFC so that it will pass through correctly and display my desired results. Below is the code of my CFC that I am calling as well as the Coding for the page that should display the desired results. The particular function that I am referring to is entitled "brother" of the component called “brother”, and the error code throw when it encounters the variable called '#meetingdate#'. Please let me know if If I am missing something. Thanks in advance for your help.

<!--- my CFC coding--->

<cfcomponent displayname="brother" hint="collect all names from brother">

     <cffunction name="meedate" hint="convert meeting date into a format that Mysql can understand" output="yes" access="public" returntype="date">

          <cfset prestartdate = form.squweekbegin>

          <cfset meetingdate = LSDateFormat(prestartdate, 'yyyy-mm-dd')>

          <cfset prestartdate2 = form.squweekbegin>

          <cfset meetingdate2 = LSDateFormat(prestartdate, 'yyyy-mm-dd')>

          <cfreturn meedate>

     </cffunction>

     <cffunction name="sfois_verify" hint="Verify that SFOID is activated in this session" output="yes" access="public" returntype="query">

               <cfquery name="sfois_verify"datasource="master">

                    SELECT sfois FROM name

               </cfquery>

          <cfreturn sfois_verify>

     </cffunction>

      <cffunction name="scapt_verify" hint="Verify that CAPT is activated in this session" output="yes" access="public" returntype="query">

          <cfquery name="scapt_verify"datasource="master">

          SELECT scapt FROM name

               </cfquery>

          <cfreturn scapt_verify>

     </cffunction>

     <cffunction name="brother" hint="0" output="yes" access="public" returntype="query">

          <cfquery name="brother" datasource="master">

                select name.foiid, meeid, meenotes, CONCAT(name.fname,' ',name.xholy) AS brother, CONCAT(name.fname) AS brothershort, CONCAT(name.fname,' ',name.xholy,' ',name.slave) AS brother3, type, meesquadlt, ltid

from name, meeting, squadlt

where not exists

(select 1

from meeting

where meefoiid = name.foiid

and meedate = '#meetingdate#'

/*and squactive = 1*/

)

AND CITY = 'richmond'

AND STATUS = 'A'

group by brother

order by type, brother

</cfquery>

<cfreturn brother>

</cffunction>

</cfcomponent>

<!--- my page displaying the results--->

<cfcookie name="constantdate" value="#form.squweekbegin#">

<cfinvoke component = "Componet.insertintoname"

method = "sfois_verify"

returnVariable = "sfois_verify">

<cfinvoke component = "Componet.insertintoname"

method = "scapt_verify"

returnVariable = "scapt_verify">

<cfinvoke component = "Componet.insertintoname"

method = "meedate"

argumentcollection="datefromformfield"

returnVariable = "meedate">

<!---is the session is HH--->

<cfif #session.user_id# EQ "#sfois_verify.sfois#" or #session.user_id# EQ "#scapt_verify.scapt#">

<cfinvoke component = "Componet.insertintoname"

method = "brother"

returnVariable = "brother">

<cfquery name="Present" datasource="master">

SELECT trim(CONCAT(name.fname,' ',name.xholy,' (',name.slave,')')) AS brother, trim(CONCAT(name.fname,' ',name.xholy)) AS brother2, trim(concat(name.fname,' ',name.slave)) AS slavename, meeid, meenotes, sfois, scapt, meeguest, meedate FROM name LEFT JOIN meeting ON meefoiid = foiid WHERE <!---<cfif #session.user_id# EQ "#sfois_verify.sfois#"> sfois = '#session.user_id#'<cfelseif #session.user_id# EQ "#scapt_verify.scapt#">scapt = '#session.user_id#' </cfif>AND --->meedate = '#meetingdate#' AND city = 'richmond' group by meefoiid order by brother

</cfquery>

<!---is the session is not HH--->

<cfelse>

<cfquery name="brother" datasource="master">

select name.foiid, meeid, CONCAT(name.fname,' ',name.xholy) AS brother, CONCAT(name.fname) AS brothershort, type, meesquadlt, ltid

from name, meeting, squadlt

where not exists

(select 1

from meeting

where meefoiid = name.foiid

and meedate = '#meetingdate#'

/*and squactive = 1*/

)

AND type = 'foi'

AND squadlt = '#session.user_id#'

AND CITY = 'richmond'

AND STATUS <> 'd'

AND STATUS <> 'T'

AND STATUS <> 'I'

AND Form4Complete <> 'no'

<!---AND Form4Complete = 'N/A'--->

group by brother

order by brother

</cfquery>

<cfquery name="Present" datasource="master">

SELECT trim(concat(name.fname,' ',name.xholy)) AS Brother, meeid, meenotes, meedate, meeguest FROM name LEFT JOIN meeting ON meefoiid = foiid WHERE squadlt = '#session.user_id#' AND meedate = '#meetingdate#' AND type = 'foi' AND city = 'richmond' group by meefoiid order by brother

</cfquery></cfif>

<cfcache action="ClientCache" timespan="#createTimeSpan(0,0,10,0)#">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">

$(document).ready(function() {

$('input:meenotes').focus(

function(){

$(this).val('');

});

$('input:meeguest').focus(

function(){

$(this).val('');

});

});

</script>

<meta name="viewport" content="width=device-width" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<style type="text/css">

@import url("SR_CSS/Attendance_css.css");

@import url("SR_CSS/media_queries.css");

@import url("SR_CSS/media_queries_ipad_portrait.css");

</style>

</head>

<body>

<div id="present">

<cfif #form.squweekbegin# NEQ "#present.meedate#"><div id="text_white_attendance">

List Is Empty For <br><br><cfoutput>#LSDateFormat(meetingdate,'DDD MMM. DD, YYYY')#</cfoutput>

<!---Content for id "text_white" Goes Here---></div>

<cfelse>

<div id="text_white_attendance">

<cfoutput>#LSDateFormat(meetingdate,'DDD MMM. DD, YYYY')#</cfoutput>

<!---Content for id "text_white" Goes Here---></div>

</cfif><!---Content for id "present" Goes Here---></div>

<cfoutput query="present">

<div id="div_present">

<a href="edit_insert_attendance1.cfm?meeid=#meeid#"><span class="div_present_current_row">#currentrow#).</span></a><a href="edit_insert_attendance1.cfm?meeid=#meeid#"> #Present.Brother#<cfif #present.meenotes# eq""><cfelseif #present.meenotes# NEQ""> - <span class="note_indicator">N</span></cfif>

<cfif #present.meeguest# eq"" or #present.meeguest# eq "0"><cfelseif #present.meeguest# NEQ""> - <span class="guest_indicator">#present.meeguest#</span></cfif></a><br /><!---Content for id "div_present" Goes Here---></div></cfoutput>

<br />

<br />

<div id="back_home_link"><a href="Home.cfm">Back to Home Page</a></div>

<br />

<br />

<form action="insert_attendance2.cfm" name="form" method="post" enctype="application/x-www-form-urlencoded">

<input type="hidden" value="<cfoutput>#meetingdate#</cfoutput>" name="meedate">

<input type="hidden" value="<cfoutput>#form.squweekbegin#</cfoutput>" name="squweekbegin">

<div id="Container_attendance">

<cfoutput query="brother">

<div id="header_name"><!---#currentrow#---> #brother.brother#<cfif #brother.type# eq"proc"> (Proc.)<cfelseif #brother.type# eq "jrfoi"> (Jr. FOI)<cfelseif #brother.type# eq"GV"> (Guest)</cfif></div>

<div id="div_radio">

<input type="radio" class="class_radio" name="meefoiid" value="#brother.foiid#" required="required">

</div><div id="div_notes"><textarea rows="5" name="meenotes" class="meenotes" placeholder="Notes on Bro. #brother.brothershort#" maxlength="255" cols="25">

</textarea></div>

<div id="div_guest"><input type="text" pattern="[0-9]*" max="3" class="class_guest" placeholder="guest" size="4" name="meeguest" value="" /></div>

<div id="div_submit"><input name="Add to attendance" class="submit_button_attendance" type="submit" value="Add - #brother.brothershort# #LSDateFormat(meetingdate,'MM/DD/YY')#" /></div></cfoutput>

<!---Content for id "attendance_container" Goes Here---></div>

</form>

<!------>

</body>

</html>

Views

506

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 23, 2015 0
LEGEND ,
Sep 24, 2015

Copy link to clipboard

Copied

I didn't look at everything you posted.  But your first function already has an issue.  There is no variable or object called "meedate".  The FUNCTION is named meedate.  But there is no meedate to return.

HTH,

^_^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 24, 2015 0
Adobe Community Professional ,
Oct 02, 2015

Copy link to clipboard

Copied

WolfShade wrote:

I didn't look at everything you posted.  But your first function already has an issue.  There is no variable or object called "meedate".  The FUNCTION is named meedate.  But there is no meedate to return.

I agree with you, WolfShade. However, it is perfectly all right for a function to return itself. For example, this is OK:

<cffunction name="meedate">

    <cfreturn meedate>

</cffunction>

But I suppose HumbleCF intended something else.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 02, 2015 0
BKBK LATEST
Adobe Community Professional ,
Oct 02, 2015

Copy link to clipboard

Copied

HumbleCF wrote:


<cffunction name="meedate" hint="convert meeting date into a format
that Mysql can understand" output="yes" access="public"
returntype="date">

          <cfset prestartdate = form.squweekbegin>

          <cfset meetingdate = LSDateFormat(prestartdate, 'yyyy-mm-dd')>

          <cfset prestartdate2 = form.squweekbegin>

          <cfset meetingdate2 = LSDateFormat(prestartdate, 'yyyy-mm-dd')>

          <cfreturn meedate>

     </cffunction>

Corrections:

1) Change returnType to String, which every caller will understand. MySQL doesn't know what a Coldfusion date is.

2) The function has no knowledge of the form. So the form variables should come into the function as arguments.

3) A function should, ideally, do just one thing. In this case, it should convert just one date.

4) It is good practice to set the function's output to No.

An example follows.

<cffunction name="meedate" hint="convert meeting date into a format that Mysql can understand" output="no" access="public" returntype="string">

         <cfargument name="inputdate" type="string" required="yes">


         <!---Convert string (that represents valid datetime in the current locale) into datetime object--->

          <cfset var localeDate = LSParseDateTime(arguments.inputdate)>

          <cfset var convertedDate= dateFormat(localeDate, 'yyyy-mm-dd')>

 

          <cfreturn convertedDate>

</cffunction>

Example usage:

<cfinvoke  method = "meedate" returnVariable = "meetingdate" component="...">

     <cfinvokeargument name="inputdate" value="#form.squweekbegin#">

</cfinvoke>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 02, 2015 0