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>
LVL 3
bhinshawnc1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.