How can I call a function in another CFC file from a function request in one cfc file?

I have one cfc file (info.cfc) with several 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 another cfc file (DateFunctions.cfc) containing 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 call addBusinessDays from a query in (info.cfc), while also creating another result column.

I thought I could 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>
+3
source share
2 answers

You can do the following with the caveat that there will be additional processing for the loop.

Edit: for discussion below, updated cfoutput for cfloop

 <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, 
            '' as Due_DATE
          FROM
             dbo.tickets    
    </cfquery>

    <cfset df = createobject("component","DateFunctions")>

    <cfloop query="records">
        <cfset records.Due_DATE = df.addBusinessDays(Days_Due, Start_Date)>
    </cfloop>

   <cfreturn records>
</cffunction>
0

df this. , . viewDate , df.

, new

<cfcomponent>

    <cfset this.df =  new DateFunctions()>

    <cffunction name="viewDate" access="remote" returntype="any" output="false" returnformat="plain">
        <cfquery  name="Local.records">
           SELECT
                dbo.tickets.Incident,
                dbo.tickets.Start_Date,
                dbo.tickets.Days_Due, 
                CAST(NULL AS datetime)
           FROM
                dbo.tickets    
       </cfquery>


      <cfloop query="Local.records">
         <cfset Local.records.Due_DATE = this.df.addBusinessDays( Local.records.Days_Due, Local.records.Start_Date)>
      </cfloop>

      <cfreturn Local.records>
    </cffunction>

<cfcomponent>
0

All Articles