Entries for month: January 2010

Configuring ColdFusion Scheduled Tasks using the CFSCHEDULE tag

ColdFusion Scheduled Tasks makes it easy to perform regular tasks, such as sending email newsletters, refresh Verity collections etc.

ColdFusion Scheduled Tasks can be configured either programatically (using the CFSCHEDULE tag)or via the ColdFusion Administrator.

Create a ColdFusion template.
Type your CFSCHEDULE code using the UPDATE action.
Save your template inside your ColdFusion application.
Run the template (i.e. open it in your browser)

Running the template will either update the ColdFusion scheduled task, or create it if it doesn't already exist. You will now see this listed in the ColdFusion Administrator under Scheduled Tasks

Syntax:




<cfschedule action="Update" task="TestSchedule"
      operation="HTTPRequest"
      url="URL"
      startdate="date"
      starttime="Time"
      interval="once">



You can also use the following code to either delete or run your tasks. Deleting it has the same effect as deleting the task via the ColdFusion Administrator




<cfschedule action = "delete" task = "TestSchedule">
<cfschedule action = "run" task = "TestSchedule">



Find More information on using the cfschedule tag Adobe Document

Remove duplicate elements from the list using coldfusion

Hi All,

List’s function is very useful in ColdFusion technology. We often use lists in our code but sometime we find duplicate elements in the list and we need to remove it. Here is the simple function to remove duplicate elements from list. Have a look at below code I hope it will helpful for you.

<cfscript>
    function removeDuplicateFromList(lst,delim){
        var Lst2 = '';
        for(i=1;i<=ListLen(lst);i++){
            value = ListGetAt(lst,i);
            if(not ListFindNoCase(Lst2,value)){
                Lst2 = ListAppend(Lst2,value,delim);
            }
        }
        return Lst2;
    }
</cfscript>

Create table and copy data from one table to another table -MSSQL

Hi All,

Today i need to create a table and copy data from one table to another table using MSSQL.

I was googling for the same and found a single statement that can do. 

Please have a look at below code. 



select * into test_new from test_old;


This code will create new table named 'test_new' and copies all data from existing 'test_old' table.

Savepoint in cftransaction

Hi All,

Coldfusion 8 has added a new attribute that can be used for setting save points for your transactions.Savepoint attribute of cftransaction tag will let us to rollback some portions of transaction. It allows you to backup your transaction to any particular intermediate point.

I'll show you how to use this attribute.
Lets have one query which has select and update operation.



<cftransaction>    
    <!--- Get data from table one --->    
    <cfquery name="getTblOne" datasource="testsqlserver">
        SELECT * FROM dbo.table_one
        WHERE Id = #tableId#
    </cfquery>
    
    <!--- This statement can't be rollback as it's not included for save point --->
    <cfquery name="updateTblOne" datasource="testsqlserver">
       UPDATE dbo.table_one SET name =  '#name#'
       WHERE id = 1
    </cfquery>
            
    <!--- Set a savepoint before the point to be rollback --->    
    <cfset point_rollback = 10>
    <cftransaction action="setsavepoint" savepoint="#point_rollback#"/>
    
    <!--- Update table one which is under save point --->
    <cfquery name="updateTblOne" datasource="testsqlserver">
       UPDATE dbo.table_one SET name =  '#name#'
       WHERE id = 1
    </cfquery>
    
    <cfquery name="getTblOne" datasource="testsqlserver">
        SELECT name FROM dbo.table_one
        WHERE Id = #tableId#
    </cfquery>
    
    <!--- If update fails or conditions below is true , roll back the transaction. --->    
    <cfif getTblOne.name eq 'testsavePoint'>
        <cftransaction action="rollback" savepoint="#point_rollback#" />
    </cfif>
</cftransaction> 


Remove null element and dangle delimiter from a list

Hello Friends,

In out day to day programming we use list. Sometimes we are getting list with some null element and dangle delimiter so we are applying code for removing null element. Today I have done simple and easy solution for that. I hope it will be helpful for you.

<cfset List1 = 'bharat,akash,,pritesh,,nirav,6,,7,'>
<b>List1</b> : <cfoutput>#List1#</cfoutput><br />
<cfset List2 = ArrayToList(ListToArray(List1,','))>
<b>List2</b> : <cfoutput>#List2#</cfoutput>

Output as per above code is
List1 : bharat,akash,,pritesh,,nirav,6,,7,
List2 : bharat,akash,pritesh,nirav,6,7

ColdFusion.navigate

Hello Friends,

Coldfusion 8 introduce new Ajax feature is ColdFusion.navigate. ColdFusion.navigate is JavaScript function which is displaying output in cfdiv, cfwindow, cfpod or cflayoutarea container. When browsers follow a link that is populated by this function, the link does not replace the page. It’s only populates the control specified by the container attribute.

Syntax:

ColdFusion.navigate (URL [, container, callbackhandler, errorhandler, httpMethod, formId])


Example:

When user clicks on the button, the ColdFusion.navigate fuction navigate the url link and displaying in the container, and then calls the callback function.

The main page looks follow:

<html>
    <head>
        <script>
            function fun_navigatePage(){
                ColdFusion.navigate('LoadPage.cfm',
                'pageContent',fun_callback,'','POST','frmNavigate');
            }
            function fun_callback(){
                document.getElementById('callbackContent').innerHTML =
                'This is call back function.';
            }
        </script>
    </head>
    <body>
        <form name="frmNavigate" id="frmNavigate" method="post">
            <label>First Name : </label>
            <input type="text" name="firstname" id="firstname" value="" />
            <br />
            <label>Last Name : </label>
            <input type="text" name="lastname" id="lastname" value="" />
            <br />
            <input type="button" name="btnNavigate" id="btnNavigate"
                    value="Navigate Page" onclick="fun_navigatePage()" />
        </form>
        <cfdiv id="pageContent" styel="background-color:##c0c0c0" />
    </body>
</html>


The Container page looks follow:

<cfoutput>
<b>FirstName</b> : #form.firstname#<br />
<b>LastName</b>  : #form.lastname#
<br />
<div id="callbackContent" style="background-color:##c0c0c0;" />
</cfoutput>

Eclipse full screen plugin.

Today i realized that i never use the toolbar of eclipse editor. I can hide it by clicking right-clicking the toolbar. The main problem was there if i save the perspective and when i restart my eclipse it doesn't stay hidden.

Then i went on a search to get if i could get rid of this thing. Fortunately i got what i needed since last one year and its really very cool and can give you wider space while coding. I'm extremely happy.

You may download this plugin from below link.
http://code.google.com/p/eclipse-fullscreen/downloads/list

Extract the file and copy jar file to eclipse plugin folder. Restart eclipse and you will see a full screen screen option under window menu of eclipse or you can hit CTRL + ALT + Z after opening your page.

Hope this post will be helping for you guys.

Hide page content when printing a page

Hello Friends,

Sometimes, we are disabled editing option in a page like [select, copy and paste] also right click disabled because of no one can copied our data. We have to also take care about printing option even disabled print option or hide page content when printing page. There is simple solution for how to hide page content when printing a page.

<style media="print" type="text/css">
   body {display:none;visibility:hidden;}
</style>

Disabled selection

<script>
    document.onselectstart = new Function('return false');
    function dataSelect(evt){return false;}
    document.onmousedown = dataSelect;
</script>

Design by Mark Aplet | Powered by Mango Blog