Posts

Deleting records using coldfusion ORM

For deleting the records, we can use the ORM function, EntityDelete(). For example, if we have an entity 'userDetails' as below: <cfcomponent persistent="true" table="Userdetails">     <cfproperty name="id" fieldType="id" ormtype="int" column="id" >     <cfproperty name="userfirstname">     <cfproperty name="userlastname">     <cfproperty name="address">     <cfproperty name="description"> </cfcomponent> For deleting the particular record, the code is given below: <cfscript> udetails= EntityLoadByPK( " Userdetails ", 1 ); EntityDelete( udetails ); </cfscript>

Ordering records using Coldfusion ORM

Image
If we have the entity as follows; component persistent="true" table=" Userdetails" {     property name="id" fieldType="id" ormtype="int" column="id" ;     property name="userfirstname"  ;     property name="userlastname";     property name="address";     property name="description"; } For ordering the records, we can use the code as follows: <cfscript> mydetails = EntityLoad( "Userdetails", {}, "id desc" ); writeDump( mydetails); </cfscript> Output:

Simple ORM concepts in coldfusion

Image
ORM (Object Relational Mapping ) helps us to develop applications without writing repetitive SQL statements for select, update, insert and delete operations. For configuring ORM, we should have a datasource in the server. Also we need to enable ORM in our Application.cfc file. So the Application.cfc will look like, component {        this.name = "ORMtest";   //Name of the Application        this.datasource = "DatasourceName";  //setting datasource        this.ormenabled = true;  //Enabling ORM        this.ormsettings.dbcreate = "update";  //Allows coldfusion to update database } For each tables in the database, we have to create different components or cfcs, which are called Entities. For example, if we have a table called 'Userdetails' , we can create a cfc 'userdetails.cfc', and  we need to map the objects to tables. component persistent="true" table=" Userdetails" {     property name="id" fieldType

Remove non ASCII characters in coldfusion

The following code will remove the non ascii or illegal characters from a string. <cfset str=" Please enter string "> <cfset a=reReplace(str, "[^\x20-\x7E]", "", "ALL")> <cfoutput>#a#</cfoutput>

Coldfusion code to get multiple mail attachments using cfimap

Below given code will loop through multiple attachments of the mail and will copy the attachments to particular folder. <cfimap action="open" connection="Conn" server="serverURL" username="useremail" password="password" secure="yes" port="portvalue"> <cfimap action="getall" connection="Conn" name="Query_getAttachments" folder="Inbox" attachmentpath="#GetTempDirectory()#" > <cfquery dbtype="query" name="getMailAttachments">       select *       from Query_getAttachments       where seen=<cfqueryparam value="no" cfsqltype="cf_sql_varchar">       and ATTACHMENTS is not null </cfquery> <cfdump var="#getMailAttachments#"> <cfloop query="getMailAttachments">       <cfif getMailAttachments.ATTACHMENTS NEQ ''>         <cfloop list="#ge

How to get the list of tasks running in coldfusion server

To get the list of tasks which are running on the server, we can use the following code: <cfobject type="JAVA" action="Create" name="factory" class="coldfusion.server.ServiceFactory"> <cfset ListOfTasks = factory.CronService.listAll()/> <cfloop index="i" from="1" to="#ArrayLen(ListOfTasks)#">     <cfdump var="#ListOfTasks[i]#" /> </cfloop>

Coldfusion Code to disable a button

<cfparam name="form.h1" default="0"> <cfif isdefined('form.h1') AND form.h1 EQ 1>     <cfoutput>The button is disabled when you submitted the form</cfoutput> </cfif> <cfform onsubmit="document.getElementById('s1').disabled = 1;" action="#cgi.SCRIPT_NAME#?#cgi.QUERY_STRING#">     <cfinput type="text" name="t1" id="t1"><br>     <cfinput type="text" name="t2" id="t2">     <cfinput type="hidden" name="h1" id="h1" value="1">     <cfinput type="submit" name="s1" id="s1" value="submit"> </cfform>