Skip to main content
Daniel_Pride
Known Participant
September 21, 2010
Answered

Passing Dates to a cfc

  • September 21, 2010
  • 3 replies
  • 6087 views

I am trying to pass a date to a  cfc and get a numeric response

I test the service in Flashbuilder and it works fine when I type in a value of 09/20/2010

It returns the numeric sum as expected....

If I change the cfc to a string and refresh the service this also works (2010/09/20)

But when I try to call it nothing and I mean nothing works.

Not this....

                   var theDate:Date = new Date();

                   sumDateLineItemsResult.token = lineItemsService.sumDateLineItems(theDate);

                     lineItemsService.commit();

nor this....
                sumDateLineItemsResult.token = lineItemsService.sumDateLineItems(new Date(2010,09,20));
                lineItemsService.commit();

nor a call with a string variable after the cfc has been modified to accept strings....

The cfc...

    <cffunction name="sumDateLineItems" output="false" access="remote" returntype="numeric" >
        <cfargument name="theDate" type="date" required="true" />
        <cfset var qSum="">
        <cfquery name="qsum" datasource="BlueRose">
             SELECT SUM(Price) AS daysTotal FROM LineItems WHERE AptDate =  <CFQUERYPARAM CFSQLTYPE="CF_SQL_DATE"                 VALUE="#ARGUMENTS.theDate#">
        </cfquery>
        <cfif len(qsum.daysTotal) EQ 0>
            <cfset qsum.daysTotal="0">
        </cfif>
        <cfreturn qsum.daysTotal>   
    </cffunction>

It seems to simple and obvious but I am stumped ! Any help from a coldfusion maven would be greatly appreciated.

Thanks

Dan Pride

This topic has been closed for replies.
Correct answer Owainnorth

Give this a go matey:

<cffunction name="sumDateLineItems" access="remote" returntype="void" >
    <cfargument name="theDate" type="any" required="true" />
    <cfmail to="me@myemail.com" from="site@mysite.com" subject="Function Arguments" type="html">
        <cfdump var="#ARGUMENTS#" />
    </cfmail>
</cffunction>

And don't you dare come back saying "but that's not my email address"

P.S.

"I am just getting into coldfusion after a long waste of time in zend  php" - glad to hear you finally left the dark side

3 replies

Known Participant
September 21, 2010

My answer to date-passing issues in any situation is usually to put my date in a clearly-defined string format (YYYYMMDD works well), pass the string, and parse it back into a date at the other end.At the moment, you've got implied conversion, and it may or may not be working the same way all the time.

Just make sure it's date, not string, when it gets into your query, or you'll slow the query down (assuming your date field is indexed).

Inspiring
September 21, 2010

Are you sure that you are using Actionscript's Date object constructor as intended?  The month parameter should be zero based.

new Date(2010,8,20).

Things to check/try:

1. Is there a communication problem between your Flex client and all services on your CF server or just this one function?

2. Use ServiceCapture or a similar tool to look at what is being sent from the client to the server.

http://www.kevinlangdon.com/serviceCapture/

Owainnorth
Inspiring
September 21, 2010

Not too sure about the Flash side, but try setting the argument type to "any", then dumping out the arguments scope to an email so you can see exactly what CF receives when you call it.

O.

Daniel_Pride
Known Participant
September 22, 2010

That sounds like a great idea, aha ! server side debugging

But I am just getting into coldfusion after a long waste of time in zend php. (etc etc )

Do I just include the cf mail tag inside the component?

Thanks for the suggestion

Dan

Owainnorth
OwainnorthCorrect answer
Inspiring
September 22, 2010

Give this a go matey:

<cffunction name="sumDateLineItems" access="remote" returntype="void" >
    <cfargument name="theDate" type="any" required="true" />
    <cfmail to="me@myemail.com" from="site@mysite.com" subject="Function Arguments" type="html">
        <cfdump var="#ARGUMENTS#" />
    </cfmail>
</cffunction>

And don't you dare come back saying "but that's not my email address"

P.S.

"I am just getting into coldfusion after a long waste of time in zend  php" - glad to hear you finally left the dark side