Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 515
  • Last Modified:

Check for condition in CFC before update

I have a cfgrid bound to a cfc. The user can update the bin, min, max or inventory count for a row.

the bind statement:
onChange="cfc:functions.updateGLC({cfgridaction},{cfgridrow},{cfgridchanged}, '#getcurruser.uid#', '#show_glc_details.GLC_ID#')"

When the user updates the inventory count I need to update the inventory date, modify date and who modified the record

If the user updates just bin, min or max I need to update the modify date and who modified the record, leaving the inventory date as is so we can tell when the last inventory took place

How can I determine which event occurs and modify the sql statement accordingly?

the cfc I use:

<cffunction name="updateGLC" access="remote" output="false">
               
        <cfargument name="cfgridaction">
        <cfargument name="cfgridrow">
        <cfargument name="cfgridchanged">        
        <cfargument name="getcurruser"> <!--- pass in modified by user id --->
       <cfargument name="glctype" required="no" type="string" default="" >
     
        <cfset strctKey=StructKeyArray(cfgridchanged) />
        <cfset strctVal=StructFindKey(cfgridchanged, strctKey[1]) />
        <cfset strctVal=strctVal[1] />  

     <cfif cfgridaction is "D">
         
   <!--- delete handled another way --->
         
     <cfelseif cfgridaction is "U">
     
            <cfquery name="update" datasource="#request.dbname#" username="#request.dbuser#" password="#request.dbpw#">
          UPDATE GLC_Inventory
         
                SET #strctKey[1]# = '#strctVal.value#',
         
          Inventory_Date = '#dateformat(CreateODBCDateTime( Now()), "mm/dd/yyyy")#',
          Modify = '#getcurruser#',
          Modify_Date =  '#dateformat(CreateODBCDateTime( Now()), "mm/dd/yyyy")#'
          WHERE ID = #cfgridrow.ID#
        </cfquery>
       
     <cfelseif cfgridaction is "I">
     <!--- insert handled another way --->
     </cfif>
        <cfreturn />
    </cffunction>
0
bhinshawnc1
Asked:
bhinshawnc1
  • 3
  • 2
1 Solution
 
_agx_Commented:
How can I determine which event occurs and modify the sql statement accordingly?

the cfgridchanged structure should contain columns that were changed. So if it contains the item count, you know you need to update the inventory date. Also add cfqueryparam to avoid sql injection risks.

             UPDATE GLC_Inventory
             SET         Inventory_Date = '#dateformat(CreateODBCDateTime( Now()), "mm/dd/yyyy")#',
                           Modify = '#getcurruser#',
                           Modify_Date =  #CreateODBCDate( Now()), "mm/dd/yyyy")#'
                          , ... other columns
                          <cfif structKeyExists(arguments.cfgridchanged , "yourItemCountColumn")>
                                 , ItemCountColumn = #val(arguments.cfgridchanged[ yourItemCountColumn ])#
                                 , Inventory_Date = '#dateformat(CreateODBCDateTime( Now()), "mm/dd/yyyy")#'
                         </cfif>
             WHERE .....
         
Be sure to use cfqueryparam to protect against sql injection. Also, if your Inventory/ModifyDate columns are type date/time, don't use strings.  Use date objects.
0
 
bhinshawnc1Author Commented:
yourItemCountColumn - is this the column number or column name ?
0
 
_agx_Commented:
It is the name of that column in your cfgrid.

Just noticed a few typos, the example should be more like

             UPDATE GLC_Inventory
             SET         Modify = '#getcurruser#',
                           Modify_Date =  #CreateODBCDate( Now()), "mm/dd/yyyy")#'
                          , ... other columns

                          <!--- if the item count changed, update it and the inventory date --->
                          <cfif structKeyExists(arguments.cfgridchanged , "yourItemCountColumn")>
                                 , ItemCountColumn = #val(arguments.cfgridchanged[ "yourItemCountColumn" ])#
                                 , Inventory_Date = '#dateformat(CreateODBCDateTime( Now()), "mm/dd/yyyy")#'
                         </cfif>
             WHERE .....
0
 
bhinshawnc1Author Commented:
Thanks for the assistance. The final implementation looked like this:

 <cfif structKeyExists(arguments.cfgridchanged , "Inventory_Count")>
            Inventory_Date = '#dateformat(CreateODBCDateTime( Now()), "mm/dd/yyyy")#',
          </cfif>
0
 
_agx_Commented:
Is Inventory_date a date/time column? If so better to use:

              Inventory_Date =  #createODBCDate(now())#

.. and don't forget cfqueryparam.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now