Mar 24 2026

ColdFusion/MSSQL – new line and LIKE


SELECT id, ownership
					FROM tbl_test
					WHERE 

				lang = <cfqueryparam cfsqltype="cf_sql_char" maxlength="2" value="en">
				and 

				(
					REPLACE(REPLACE(ownership, CHAR(13), ''), CHAR(10), '') like <cfqueryparam value="%#reReplace(arguments.real_beneficiaries, "[\r\n]", "", "all")#%" cfsqltype="cf_sql_nvarchar">
					OR
					REPLACE(REPLACE(ownership, CHAR(13), ''), CHAR(10), '') like <cfqueryparam value="#reReplace(arguments.real_beneficiaries, "[\r\n]", "", "all")#%" cfsqltype="cf_sql_nvarchar">
					OR
					REPLACE(REPLACE(ownership, CHAR(13), ''), CHAR(10), '') like <cfqueryparam value="%#reReplace(arguments.real_beneficiaries, "[\r\n]", "", "all")#" cfsqltype="cf_sql_nvarchar">
					OR
					REPLACE(REPLACE(ownership, CHAR(13), ''), CHAR(10), '') = <cfqueryparam value="#reReplace(arguments.real_beneficiaries, "[\r\n]", "", "all")#" cfsqltype="cf_sql_nvarchar">

					)

Nov 28 2024

Coldfusion – remove duplicates from array using struct

<cfset myArray = ["apple", "banana", "apple", "orange", "banana"]>

<!-- Use a struct to remove duplicates -->
<cfset uniqueStruct = {}>

<cfloop array="#myArray#" index="item">
    <cfset uniqueStruct[item] = true>
</cfloop>

<!-- Convert struct keys back to array -->
<cfset uniqueArray = StructKeyArray(uniqueStruct)>

<cfdump var="#uniqueArray#">

Jun 5 2024

Coldfusion – inline if else

<!--- Syntax: ((condition) ? trueStatement : falseStatement) --->
<cfset width = ((ThumbnailWidth EQ 0) ? 75 : ThumbnailWidth) />

Jun 1 2024

ColdFusion – send email using cfscript


// Create an instance of the mail object
mail=new mail();

// Set it's properties
mail.setSubject( "Sample Email" );
mail.setTo( "to@example.com" );
mail.setFrom( "from@example.com" );
mail.setCC( "cc@example.com" );
mail.setBCC( "bcc@example.com" );

// Add an attachment
mail.addParam( file="C:\foo.txt" );

// Add email body content in text and HTML formats
mail.addPart( type="text", charset="utf-8", wraptext="72", body="This is a test message." );
mail.addPart( type="html", charset="utf-8", body="<p>This is a test message.</p>" );

// Send the email
mail.send();

source: https://stackoverflow.com/questions/8423276/how-do-you-send-an-email-with-an-attachment-using-cfscript-in-cf9


Jan 28 2024

ColdFusion – OutOfMemoryError – GC overhead limit exceeded

“This error essentially means that you need to add more memory, or reconfigure your garbage collection arguments. You can suppress this error by adding -XX:-UseGCOverheadLimit to your JVM startup arguments”

Note to self – don’t do it! It will block your entire windows virtual machine! Already seen and done!!!

source:

https://www.petefreitag.com/blog/outofmemoryerror-gc-overhead/


Jan 4 2024

ColdFusion – csv file BOM Header problem CF2023

I’m running cf2023 on windows and I’m having a weird problem with basic functionality that was working normally on the cf2016 version I was using earlier.
Every attempt to generate a csv file in which the Croatian characters will be displayed correctly has so far been unsuccessful.

I tried changing the JVM arguments and adding -Dfile.encoding=UTF8 but it didn’t help.

BOM header problem – adding #CHR(65279)# to the beginning of the csv content helped.


<cfprocessingdirective pageencoding="utf-8">

<cfset content = '#CHR(65279)#priča;požarevac;PRIŠTINA;ČAKOVEC;ŽUPANJA;ĐAKOVO;rođak'>

<cffile action="write"
	file="#expandPath('temp')#/test.csv"
	output="#content#"
	addnewline="yes" charset="utf-8">

source: https://community.adobe.com/t5/coldfusion-discussions/adding-utf-8-bom-byte-order-mark-to-file-output/m-p/11745053


Apr 9 2021

Coldfusion – queryOfQueries union – not elegant but effective :)


<cfset Local.currencies = arrayNew(1)>
 <cfset arrayAppend(Local.currencies, 'EUR')>
 <cfset arrayAppend(Local.currencies, 'HRK')>
 <cfset arrayAppend(Local.currencies, 'BGN')>
 <cfset arrayAppend(Local.currencies, 'RON')>

 <cfset currencyList = structNew()>

 <cfloop from="1" to="#arrayLen(Local.currencies)#" index="a">

 <cfset local.currency = structNew()>

 <cfset local.currency.currency = Local.currencies[a]>

 <cfset arguments.currency = Local.currencies[a]>

 <cfset local.currency.query = get_paiment_report_Query(argumentCollection = arguments)>

 <cfset currencyList[local.currency.currency] =  local.currency>

 </cfloop>

 <cfquery name="q_payments" dbtype="query" result="queryResult">

 <cfset var count = 0>

 <cfloop collection="#currencyList#" item="key"  >

 <cfif currencyList[key].query.recordcount neq 0>

 <cfset count = count+1>

 <cfif count gt 1 >

 UNION

 </cfif>

 SELECT * FROM currencyList.#key#.query

 </cfif>

 </cfloop>

 </cfquery>

Apr 9 2021

ColdFusion – queryOfqueries union – elegant

private any function combineQuery(qA, qB) {
 var qry1Result = arguments.qA;
 var qry2Result = arguments.qB;
 var qoqResult = '';

// create new query object
 var qoq = new Query();

// set attribute of new query object to be a query result with arbortrary name

qoq.setAttributes(QoQsrcTableA = qry1Result);
 qoq.setAttributes(QoQsrcTableB = qry2Result);

// use previously set attribute as table name for QoQ andset dbtype = query
 qoqResult = qoq.execute(sql="select * from QoQsrcTableA union select * from QoQsrcTableB", dbtype="query");

// return result
 return qoqResult.getResult();

}

source: https://coldfusion.adobe.com/2017/10/unioning-queries-using-query-of-query/


Feb 17 2021

ColdFusion – get file name before cffile upload

<cffunction name="getClientFileName" returntype="string" output="false" hint="">
	<cfargument name="fieldName" required="true" type="string" hint="Name of the Form field" />

	<cfset var tmpPartsArray = Form.getPartsArray() />

	<cfif IsDefined("tmpPartsArray")>
		<cfloop array="#tmpPartsArray#" index="local.tmpPart">
			<cfif local.tmpPart.isFile() AND local.tmpPart.getName() EQ arguments.fieldName>
				<cfreturn local.tmpPart.getFileName() />
			</cfif>
		</cfloop>
	</cfif>

	<cfreturn "" />
</cffunction>

source: http://www.stillnetstudios.com/get-filename-before-calling-cffile/


May 19 2020

Coldfusion – get PDF page count


<cfpdf action="getInfo" source ="test.pdf" name="PDFInfo">
<cfset pageCount = "#PDFInfo.TotalPages#" >