samedi 11 juin 2016

How can I call a function in another CFC file from within a query of a function in one cfc file?

I have one cfc file (info.cfc) with multiple functions as shown below.

<cfcomponent output="true" extends="DateFunctions">
    <cffunction name="getStatuses" access="remote" returntype="any" output="true" returnformat="plain">
       ...
    </cffunction>

    <cffunction name="viewDate" access="remote" returntype="any" output="true" returnformat="plain">
        <cfquery  name="records">
              SELECT
                 dbo.tickets.Incident,
                 dbo.tickets.Start_Date,
                 dbo.tickets.Days_Due
              FROM
                 dbo.tickets    
        </cfquery>
    </cffunction>
</component>

And the other cfc file (DateFunctions.cfc) containing the a function with two arguments and returning a date. The DateFunctions.cfc file is as follows:

<cfcomponent output="true" name="DateFunctions"">
    <cffunction name="addBusinessDays" access="remote" returntype="any" output="true" returnformat="plain">
       <cfargument name="daysToAdd" 
                required="yes" 
                type="numeric" 
                hint="The number of whole business days to add or subtract from the given date">
        <cfargument name="date" 
                required="No" 
                type="date" 
                hint="The date object to start counting from.." 
                default="#NowDateTime#">

         ...
         ... <!--- Perform some tasks --->

         <cfreturn Date>
    </cffunction>
</cfcomponent>

Question: How can I invoke "addBusinessDays" from within the query in (info.cfc) also producing another column of results.

I thought I might have been able to do something like:

<cffunction name="viewDate" access="remote" returntype="any" output="true" returnformat="plain">
    <cfquery  name="records">
          SELECT
             dbo.tickets.Incident,
             dbo.tickets.Start_Date,
             dbo.tickets.Days_Due,
             (
               <cfinvoke component="DateFunctions" method="addBusinessDays" returnVariable="Date">
                  <cfinvokeargument name="daysToAdd" value="#dbo.tickets.Days_Due#">
                  <cfinvokeargument name="date" value="#dbo.tickets.Start_Date#">
               </cfinvoke>
             ) AS Due_DATE
          FROM
             dbo.tickets    
    </cfquery>
</cffunction>

Aucun commentaire:

Enregistrer un commentaire