http://coldfusion.com logo
Join Slack
Powered by
# cfml-beginners
  • s

    Simone

    01/28/2022, 7:19 PM
    what is the best better for this kind
    if (IsDefined("myquery.startDate") ) {
    d
    a
    f
    • 4
    • 6
  • e

    epipko

    02/07/2022, 5:21 PM
    I have the following try/catch block, but still get this error: Element QUERYERROR is undefined in CFCATCH. What am I not doing to catch it?
    Copy code
    <CFTRY>
    	<cfstoredproc procedure="UPDATE_PKG.MAIN_P" datasource="#REQUEST.prod#">
    		<cfprocparam type="In" value=#FORM.sales_order_number# cfsqltype="CF_SQL_INTEGER">
    		<cfprocparam type="In" value=#FORM.division_id# cfsqltype="CF_SQL_VARCHAR">
    	</cfstoredproc>
    	
    	<cfoutput>
    		<h3 align="left">Success</h3>
    		<p></p><a href="#CGI.http_referer#">Go Back</a>
    	</cfoutput>	
    
    	<CFCATCH TYPE = "Database">
    		<cfoutput>   
    			Something went wrong :-( Contact your system administrator<br />
    			#cfcatch.queryError#			
    		</cfoutput>
     	</CFCATCH>
    </CFTRY>
    m
    a
    • 3
    • 11
  • a

    Adam Cameron

    02/10/2022, 6:31 PM
    @nickg I did not want to clutter your other thread, but this is important to understand: Encoding concepts: • when transmitting character data, the transmission needs to say what charset the data is in so the receiver knows how to interpret it. This is charset encoding, and with HTTP or MIME messages, this is done with a header. • when a user agent (browser, email client) renders a document that has been received via the mechanism in the previous step, one can provide additional meta information that re-states this, eg like in a
    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
    . Note the
    http-equiv
    ... it is the document-level equivalent of the HTTP header mentioned in the previous phase. I think on the whole these days this is a nice to have, and the header in the transmission is enough? Don't quote me on that. • when being rendered as part of an HTML document (for example), user-originated data must be security- / intended-usage- encoded before it's rendered, so protect from XSS, and to just make sure it's rendered correctly. A benign example would be that if we were using an HTML client now, and if I wanted actual
    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
    to appear on the screen for you to read, instead of having the browser goes "oh that's info for me", I need to encode it (escape it, basically). So in your CFML view file, never this:
    Copy code
    <cfoutput>#someVariable#</cfoutput>
    But always:
    Copy code
    <cfoutput>#encodeForHtml(someVariable)#</cfoutput>
    unless you are actively outputing markup that should be treated as mark-up. This however is generally a pretty rare thing to be wanting to do. (note: there are other encoding functions to use for different situations in the HTML document, eg:
    encodeForHtmlAttribute
    and
    encodeForJs
    etc. Use the correct one).
    👍 5
    n
    • 2
    • 2
  • m

    Mike Vierow

    02/11/2022, 11:04 PM
    Is it possible to get recordcount in nested cfoutputs when using query and group attributes? ie
    <cfquery name="test">select firstname from names order by firstname asc</cfquery>
    <cfoutput query="test" group="firstname">
    <cfoutput>
    #test.recordcount# <!--- total number of people with this first name --->
    </cfoutput>
    </cfoutput>
    m
    a
    +2
    • 5
    • 13
  • s

    Simone

    02/13/2022, 3:22 PM
    i am running one query under mysql and trying to convert the columns to array but the issue is, it is taking concat and breaking it in wrong way, my query (what ia m using is ListToArray(k,","), now i want it to consider concat as one single list instead of breaking it in multiple arrays, how can i fix it, any clues
    Copy code
    var k = tblviews.viewsID, concat('<a href=<http://localhost:11000/project1/views_view.cfm?849402E6-E905-790C-E0083357100F99CE=849402E7-01A6-D87F-EDF2EBE1F5ADCBF6&viewsID=2922J07C52B45E706494A8B8687C8CB864568AA8906490B09C7C6E48B6BC9E425088BE441&Task=color>>',tblviews.viewsTitle, '<small>(',tblviews.viewsID,')</small></a>') as viewsTitle, tblviews.viewsManager_ContactID, tblviews.EndDate_Scheduled, tblviews.viewsViews_Target, tblsection.sectionName, tblcontact.FirstName, tblcontact.LastName
    m
    • 2
    • 2
  • f

    Formiko

    02/15/2022, 2:17 AM
    SELECT amount from total_cash. if I then output the query and the query output $10 $34 $26 how do I add all of them up? Would I first put each query into a separate variable?
    d
    • 2
    • 2
  • f

    Formiko

    02/17/2022, 8:22 PM
    This is what I have. It was answered a few days ago, but I deleted the file accidentally ŭere I solved the problem. <cfquery name="expense" datasource="expense_db" username = "foo" password = "bar"> SELECT amount, expense_date, description, sum(amount) FROM expense </cfquery> I then have <cfoutput query="expense"> #sum(amount)# </cfoutput> The error I got was "No matching function [SUM] found" but that didn't happen last time. I forgot what I did!
    m
    d
    +2
    • 5
    • 35
  • f

    Formiko

    02/17/2022, 8:24 PM
    While I'm at it. How can I put #sum(amount)# in a variable? I want to subtract let's say 100-#sum(total)# ?
    m
    • 2
    • 1
  • s

    Simone

    02/18/2022, 2:37 PM
    anyone has worked with salesforce when adding an activity and history, i am getting an error Entity Type cannot be inserted: Activity History
    m
    • 2
    • 2
  • j

    johnbarrett

    02/20/2022, 1:58 AM
    I am having real trouble transferring a tabled-based contact form to a CSS form. What could I be doing wrong? The table-based form works, I thought that I would change <td> and <tr> to <div>, but that didn't work. This may be off-topic.
    d
    a
    d
    • 4
    • 10
  • j

    johnbarrett

    02/21/2022, 6:09 PM
    Does anybody know where the docs are for Solr? I am trying to build a search engine in ColdFusion. I have searched google, but not found much. I know I use <cfcollection> to get started, but don't know where to start so I want to read the docs from Adobe.
    m
    • 2
    • 3
  • j

    johnbarrett

    02/28/2022, 3:06 AM
    My Application.cfc file has (see below): In my <cfquery> I can't use #datasource# or I get qet blank page, but if I use cfhawaii everything works. am I doing something wrong?
    Copy code
    component {
    
        this.name = "myApplication";
        this.applicationTimeout = CreateTimeSpan(0, 2, 0, 0); //2 hours
        this.datasource = "cfhawaii";
        this.sessionManagement = true;
        this.sessionTimeout = CreateTimeSpan(0, 0, 30, 0); //30 minutes
        this.customTagPaths = [ expandPath('/myAppCustomTags') ];
    
        function onApplicationStart() {
            return true;
        }
    
        function onSessionStart() {}
    
        // the target page is passed in for reference,
        // but you are not required to include it
        function onRequestStart( string targetPage ) {}
    
        function onRequest( string targetPage ) {
            include arguments.targetPage;
        }
    
        function onRequestEnd() {}
    
        function onSessionEnd( struct SessionScope, struct ApplicationScope ) {}
    
        function onApplicationEnd( struct ApplicationScope ) {}
    
        function onError( any Exception, string EventName ) {}
    
    }
    d
    a
    +2
    • 5
    • 10
  • r

    Rick Morayniss

    03/03/2022, 9:25 PM
    Here is the AllFunctions cfc file. <cfcomponent displayname="Allfunctions" output="false" hint="Handle the application." > <cffunction name="addingFunction" access="public" returnType="numeric"> <cfargument name="firstNumber" type="numeric" required="true"> <cfargument name="secondNumber" type="numeric" required="true"> <cfset var sumOfThem = arguments.firstNumber + arguments.secondNumber> <cfreturn sumOfThem> </cffunction> </cfcomponent> Here is the FuntionTest CFML file. <cfinclude template="AllFunctions.cfc"> <cfoutput> <H1> #AllFunctions.addingFunction(5,2)# </H1> </cfoutput> Yet I get the following error Variable ALLFUNCTIONS is undefined.
    m
    f
    +2
    • 5
    • 14
  • j

    johnbarrett

    03/04/2022, 4:15 AM
    How can I write the date to MySQL with ColdFusion? I tried
    #CreateODBCDate(Now)#
    However I get an error, so I know that this is wrong. Any help would be greatly appreciated
    p
    a
    a
    • 4
    • 12
  • j

    johnbarrett

    03/05/2022, 12:27 AM
    What is the best way of stopping duplicates to your MySQL database with ColdFusion? I have searched Google but didn't find anything helpful. Below is my query, I am really lost on this one, and would appreciate any help.
    Copy code
    <cfquery name="Insert">                                                                                                      INSERT INTO users(first_name, last_name, date)
    VALUE("#form.first_name#", "#form.last_name#", "#CreateODBCDate(Now())#");
     </cfquery>
    d
    d
    +4
    • 7
    • 25
  • r

    Rick Morayniss

    03/07/2022, 2:53 PM
    I am taking over CF software and a number of the files appear to be binary cfm files, how do I de-compile it so I can see and modify the source code?
    a
    b
    • 3
    • 4
  • n

    Nicole Liliana

    03/10/2022, 1:08 PM
    Hy everybody CacheBox question, i need to put one view in cache, the CacheBox create an object in the region, when users see the view, they “use” the same object or there are many objects with the same view? PS. Sorry for the english, i’m not very good at writing
    b
    • 2
    • 2
  • e

    epipko

    03/10/2022, 6:04 PM
    CF 2018 on Win 2016 I wrote a app that loads .xls files into Oracle database (and doing something else in the process). I have to convert .xls file into .csv in order to do so. My code breaks when user deletes lots os entries from the original .xls file, which results in the following:
    Copy code
    CUSTOMER_ID,DIVISION_ID,STYLE_ID,QUANTITY
    AMAZON,YMS,Y15CXWE,31
    AMAZON,YMS,Y15CXWE,85
    ,,,
    ,,,
    ,,,
    ,,,
    Question: how can I remove lines with commas ONLY in them?
    a
    d
    +2
    • 5
    • 22
  • r

    Rick Morayniss

    03/11/2022, 9:52 PM
    How do I add previous created files to a project in cf builder?
    s
    • 2
    • 3
  • m

    Mr M

    03/19/2022, 2:19 PM
    I was trying to get through the beginner tutorial. All was rolling along well until I got to the part about adding a second action. When you hover over the "goodbye" you only see it link to the controller and it won't show the action (see bottom left corner). Anyone know what is this issue?
    a
    p
    • 3
    • 3
  • s

    Simone

    03/19/2022, 8:25 PM
    i have a table like this where i am trying to get the correct answer value https://prnt.sc/L87XA1sl89Ie written a function like this, but it is not picking up the value anything wrong i am doing here
    Copy code
    <cffunction name="getCorrectAnswer" returntype="any" output="true" hint='Gets the correct answer'>
    		<cfargument name="questionidfk" type="UUID" required="true">
    		
    		<cfset var rsQuery=querynew('')>
    		<cfset var answer = ''>
    		
    			<cfquery name="rsIdfromQuestion" datasource="#variables.dsn#">
    				select id  
    				from questions   
    				where questionnaireidfk = <cfqueryparam value="#arguments.questionidfk#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> 
    			</cfquery>
    			<cfloop query="rsIdfromQuestion">
    				<cfquery name="rsQuery" datasource="#variables.dsn#">
    					select correctAnswer,rank,answer,a_id,id,ROW_NUMBER() OVER(ORDER BY id ASC) AS Row   
    					from answers 
    					where questionidfk = <cfqueryparam value="#rsIdfromQuestion.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> 
    					AND correctAnswer IS NOT NULL
    				</cfquery>
    				<cfset answer = request.udf.ParagraphFormat2(rsQuery.answer)>
    				<cfreturn answer>
    			</cfloop>
    		</cfif>	
    	</cffunction>
    a
    m
    • 3
    • 4
  • e

    epipko

    03/24/2022, 9:59 PM
    CF2018 on Win2016 I am trying to install and configure DataTables. I downloaded and unzipped it in to
    \\cf01\d$\DataTables
    folder. Trying it using code below, but it does not work. What am I missing?
    <HTML>
    <HEAD>
    <TITLE>Data Tables</TITLE>
    <link rel="stylesheet" type="text/css" href="DataTables/datatables.min.css">
    <script type="text/javascript" charset="utf8" src="DataTables/datatables.min.js"></script>
    </HEAD>
    <table id="table_id" class="display">
    <thead>
    <tr>
    <th>Column 1</th>
    <th>Column 2</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>Row 1 Data 1</td>
    <td>Row 1 Data 2</td>
    </tr>
    <tr>
    <td>Row 2 Data 1</td>
    <td>Row 2 Data 2</td>
    </tr>
    </tbody>
    </table>
    </BODY>
    </HTML>
    d
    m
    • 3
    • 71
  • f

    Formiko

    04/04/2022, 7:33 PM
    <!--- Get full path to mp3s. ---> <cfset mp3Directory = expandPath(".")> <!--- Get directory ---> <cfdirectory action="list" directory="#mp3Directory#" name="mp3s" filter="*.mp3"> <!--- Do we have any mp3s? ---> <cfif mp3s.recordCount gt 0> <!--- How many mp3s? ---> <cfset totalMp3s = mp3s.recordCount> <!--- Pick one ---> <cfset pickedIndex = randRange(1, totalMP3s)> <!--- get the file ---> <cfset mp3 = mp3s.name[pickedIndex]> <!--- play it ---> <!---<cfoutput><img src="#image#"></cfoutput>---> <cfoutput><cfmediaplayer name="DJ" autoplay="true" source="#mp3#" controlbar="true" quality="high"></cfoutput> </cfif>
    s
    • 2
    • 5
  • e

    epipko

    04/07/2022, 4:14 PM
    I need to parse Json file in CF2018. I copied json data into returnly_json.txt file and placed it into c:\temp directory on the server. When I try
    <cfif isJSON(\\server\c$\Temp\returnly_json.txt)>
    , I am getting this error:
    Invalid CFML construct found on line 85 at column 18.
    ColdFusion was looking at the following text:
    //
    . What am I doing wrong?
    m
    s
    • 3
    • 25
  • f

    Formiko

    04/11/2022, 2:48 AM
    I'm trying to perform form validation here in my code: <cfinput type="text" name="name" value="" maxlength="100" validateat="onBlur" validate="required,name" message="you must enter a name" /> I'm using lucee via command box, when I execute that page, I get this error attribute validateAt is not supported for tag input Que pasa?
    b
    • 2
    • 4
  • n

    Nikola Mikasinovic

    04/12/2022, 12:37 PM
    can someone help me, i want to update my query without reloading my page. It depents on what you have selected in the first select tag and the options of the second select tag denpends on the first one. How can I solve it without reloading my page? <cfquery name="optionBez" datasource="Kiwanis"> SELECT DISTINCT OpNr, OpID, opGENr, OpBez#session.sprache# AS OptBezeichnung FROM tblGEOptions INNER JOIN tblAnlass ON tblAnlass.GEOpt = tblGEOptions.opNr WHERE (IDDist = #session.curDist#) AND (#Event.GENr# = opGENr); </cfquery> <cfquery name="GEBezeichnung" datasource="Kiwanis"> SELECT conKey, conBezeichnung, geTyp, conDatumbis, conDatumVon, conBezeichnung + ' '+ conOrt AS Bezeichnung FROM tblConventions WHERE (conDistrict = #session.curDist#) AND (conJahr > #session.kjahr-1#) AND (GETyp = 'DC') ORDER BY conDatumVon; </cfquery> <div class="col-lg-6 col-12 form-inline"> <i>GE</i> &nbsp; <select class="form-control col-lg-6" id="GENummer" name="GENummer" onchange="GEChange(this.value)"> <option value="0"></option> <cfif Dates EQ #DateFormat(Event.Datum_von,'dd.mm.yyyy')#> <cfloop query="GEBezeichnung"> <!---<cfif Dates EQ #DateFormat(conDatumVon,"yyyy-mm-dd")#>---> <cfset Wert = "#Bezeichnung# #DateFormat(conDatumVon,"dd.mm.yyyy")#"> <cfif #conKey# EQ #Event.GENr#> <option value="#conKey#" selected>#Wert#</option> <cfelse> <option value="#conKey#">#Wert#</option> </cfif> <!---</cfif>---> </cfloop> </cfif> </select> &nbsp;&nbsp;<i>Option</i> &nbsp; <select class="form-control col-lg-4" name="GEOption" id="GEOption"> <option value="0"></option> <cfloop query="optionBez"> <cfif #Event.GEOpt# EQ #opNr#> <option value="#opNr#" selected>#optBezeichnung#</option> <cfelse> <option value="#opNr#">#optBezeichnung#</option> </cfif> </cfloop> </select> </div>
    a
    p
    • 3
    • 8
  • f

    Formiko

    04/12/2022, 11:11 PM
    I found code on github that is using cfsessionswap tag. It doesn't run on lucee and I can't seem to find it on adobe, is this a newer adobe tag? what does it do?
    s
    a
    a
    • 4
    • 3
  • f

    Formiko

    04/17/2022, 7:24 PM
    How do I search extracted pdf text? I extracted a PDF like so: <cfpdf action="extracttext" source="Mornings-with-Tozer.pdf" name="tozer" /> <cfcontent type="text/html" /> <cfoutput>#tozer#</cfoutput> How do I search for let's say March 2 and then display that content?
    a
    • 2
    • 21
  • e

    epipko

    04/19/2022, 5:42 PM
    I am converting UTC date into Oracle-friendly date as this:
    <cfset x = #dateTimeFormat(lsParseDateTime(DateConvert("UTC2Local", "2021-12-09T15:11:32.273Z")), 'MM/DD/YYYY hh:nn:ss')#>
    <cfoutput>#x#</cfoutput>
    and getting this: 12/08/2021 111132 How do I convert back to "*2021-12-09T151132.273Z*" format?
    a
    b
    m
    • 4
    • 20
  • e

    epipko

    04/22/2022, 3:43 PM
    Could someone please explain how to get to the "attributes" structure. I need to get to "carrier" and "tracking_number". Code below returns correct result
    <cfset jsonData = deserializeJSON(httpResp.fileContent) />
    <cfset return_line_items = jsonData.included>
    <cfloop array=#return_line_items# index="i">
    <cfset line_item_id = #i.id#>
    <cfset line_item_type = #i.type#>
    <cfoutput>
    Line_item_id:   #line_item_id#<br />
    Line_item_type: #line_item_type#<br />
    </cfoutput>
    <br />
    </cfloop>
    , but when I try to get to carrier this way, I am receiving the error: "Invalid collection .... Must be a valid structure or COM object."
    <cfif #i.type# EQ "shipping_labels">
    <cfloop collection="#jsonData.included#" item="k">
    <cfset carrier = #jsonData.included.attributes.[k].carrier#>
    <cfoutput>#carrier#<br /></cfoutput>
    </cfloop>
    </cfif>
    a
    d
    j
    • 4
    • 13
12345...8Latest