Search code examples
coldfusioncfccfml

Getting data from the function using an Object in CF


I have a CFC object and a function which gets me the data which I want. Now I want to use that data and provide it to an already defined custom tag attribute. When I dump the #iEngine.listScore()# I get some parameters. But my problem is how should I provide those to an attribute?

<cfdump var="#iEngine.listScores()#" label="Swapnil Test - Function ListScore">     
<cfset filename="ACE_DataExtract_#DateFormat(now(),'dd.mmm.yyyy')#.xls" />
<!--- Calling Custom tags to create/output xls files --->
<cfmodule template="#request.library.customtags.virtualpath#excel.cfm" file="#filename#" sheetname="ACE Report">

  <cfmodule template="#request.library.customtags.virtualpath#exceldata.cfm"
    query="#iEngine.listScores()#" 
    action="AddWorksheet" 
    sheetname="ACE Report" 
    colorscheme="blue" 
    useheaders="true" 
    contentformat="#{bold=true}#"
    customheaders="#ListScore#">
      <cfoutput>Excel Extract - ACE Report - #DateFormat(Now(),"d-mmm-yyyy")#</cfoutput>
  </cfmodule>   
</cfmodule>

Here I want to provide the data of iEngine.listScore() to the "Query" attribute in "exceldata" custom tag.

Below is the dump of iEngine.listScore()

Dump of iengine.listscore


Solution

  • I would write a transform Data function to change your array-struct to a query object, then pass that on....

    <cffunction name="transformData" result="query">
        <cfargument name="inArray" type="array">
    
        <cfset local.qryReturn = queryNew("actiondate,actionId,closedate")>
        <!--- You may look up queryNew and also set your dataTypes --->
    
        <cfloop array="#arguments.inArray#" index="i">
            <cfset QueryAddRow(local.qryReturn)>
            <cfset querySetCell(local.qryReturn,"actionDate",i["actiondate"])>
            <cfset querySetCell(local.qryReturn,"actionid",i["actionid"])>
            <cfset querySetCell(local.qryReturn,"closedate",i["closedate"])>
        </cfloop>
    
        <cfreturn local.qryReturn>
    </cffunction>
    
    <cfset test = [
        {actiondate='1/1/2015',actionid=134,closedate=''},
        {actiondate='1/2/2015',actionid=135,closedate=''},
        {actiondate='1/3/2015',actionid=136,closedate=''}
    ]>
    
    <cfdump var="#test#">
    
    <cfset resultQry = transformData(test)>
    <cfif NOT isquery(resultQry)>
        Exit invalid Data.
    <cfelse>
        <cfdump var="#resultQry#">
    </cfif>