bhinshawnc1
asked on
cfgrid cfquery update
I display an inventory to the user for a location and allow them to edit Bin, Min, Max and Inventory Count.
<cfform name="GridForm" action="update_glc_invento ry.cfm">
<cfgrid name="modify_glc_inventory "
height=425
autowidth="yes"
width=1020
vspace=10
selectmode="edit"
query="search_query"
insert="No"
delete="No"
format="html"
selectonload = "no"
striperows = "yes"
selectcolor="CDE6F3">
<cfgridcolumn name="ID"
header="ID"
width=40
headeralign="center"
headerbold="Yes"
select="No"
display="No">
<cfgridcolumn name="PID_ID"
header="PID"
width=50
headeralign="center"
headerbold="Yes"
select="No">
<cfgridcolumn name="Description"
header="Description"
width=150
headeralign="center"
headerbold="Yes"
select="No">
<cfgridcolumn name="MOQ"
header="MOQ"
width=30
headeralign="center"
headerbold="Yes"
select="No">
<cfgridcolumn name="COST"
header="Cost"
width=50
headeralign="center"
headerbold="Yes"
select="No">
<cfgridcolumn name="UNIT"
header="Unit"
width=50
headeralign="center"
headerbold="Yes"
select="No">
<cfgridcolumn name="BIN"
header="BIN"
width=50
headeralign="center"
headerbold="Yes"
select="Yes">
<cfgridcolumn name="MIN"
header="MIN"
width=30
headeralign="center"
headerbold="Yes"
select="Yes">
<cfgridcolumn name="MAX"
header="MAX"
width=30
headeralign="center"
headerbold="Yes"
select="Yes">
<cfgridcolumn name="Inventory_Count"
header="Inventory"
width=50
headeralign="center"
headerbold="Yes"
select="Yes">
<cfgridcolumn name="Inventory_Date"
header="Inventory Date"
width=60
headeralign="center"
headerbold="Yes"
select="No"
type="date">
</cfgrid>
<cfinput name="submitit" type="Submit" value="Submit">
</cfform>
I pass that to the update page update_glc_inventory.cfm
<html>
<head>
<title>Catch submitted grid values</title>
</head>
<body>
<h3>Grid values for Form.modify_glc_inventory row updates</h3>
<cfif isdefined("Form.modify_glc _inventory .rowstatus .action")>
<cfloop index = "counter" from = "1" to =
#arraylen(Form.modify_glc_ inventory. rowstatus. action)#>
<cfoutput>
The row action for #counter# is:
#Form.modify_glc_inventory .rowstatus .action[co unter]#
<br>
BIN = #Form.modify_glc_inventory .BIN[count er]#
<br>
MIN = #Form.modify_glc_inventory .MIN[count er]#
<br>
MAX = #Form.modify_glc_inventory .MAX[count er]#
<br>
Inventory_Count= #Form.modify_glc_inventory .Inventory _Count[cou nter]#
<br>
Inventory_Date= #dateformat(CreateODBCDate Time( Now()), "mm/dd/yyyy")#
<br>
Modify = '#getcurruser.uid#',
<br>
Modify_Date = '#dateformat(CreateODBCDat eTime( Now()), "mm/dd/yyyy")#'
<br>
</cfoutput>
<cfif Form.modify_glc_inventory. rowstatus. action[cou nter] is "D">
<cfquery name="DeleteExisting" datasource="#dbname#" username="#dbuser#" password="#dbpw#">
<!--- DELETE FROM GLC_Inventory don't delete just set inactive in case recover needed --->
UPDATE GLC_Inventory
SET ACTIVE_STATUS = 2
WHERE ID=<cfqueryparam
value="#Form.modify_glc_in ventory.or iginal.ID[ counter]#"
CFSQLType="CF_SQL_INTEGER" >
</cfquery>
<cfelseif Form.modify_glc_inventory. rowstatus. action[cou nter] is "U">
<cfquery name="UpdateExisting" datasource="#dbname#" username="#dbuser#" password="#dbpw#">
UPDATE GLC_Inventory
SET
<!------>
<cfif Form.modify_glc_inventory. BIN[counte r] neq "">
BIN=<cfqueryparam
value="#Form.modify_glc_in ventory.BI N[counter] #"
CFSQLType="CF_SQL_VARCHAR" maxlength="25" >,
</cfif>
<cfif Form.modify_glc_inventory. MIN[counte r] neq "">
MIN=<cfqueryparam
value="#Form.modify_glc_in ventory.MI N[counter] #"
CFSQLType="CF_SQL_INTEGER" >,
</cfif>
<cfif Form.modify_glc_inventory. MAX[counte r] neq "">
MAX=<cfqueryparam
value="#Form.modify_glc_in ventory.MA X[counter] #"
CFSQLType="CF_SQL_INTEGER" >,
</cfif>
Inventory_Count=<cfquerypa ram
value="#Form.modify_glc_in ventory.In ventory_Co unt[counte r]#"
CFSQLType="CF_SQL_INTEGER" >,
Inventory_Date='#dateforma t(CreateOD BCDateTime ( Now()), "mm/dd/yyyy")#',
<!--- <cfqueryparam
value="#Form.modify_glc_in ventory.In ventory_Da te[counter ]#"
CFSQLType="CF_SQL_DATE" >, --->
Modify = '#getcurruser.uid#',
Modify_Date = '#dateformat(CreateODBCDat eTime( Now()), "mm/dd/yyyy")#'
WHERE ID=<cfqueryparam
value="#Form.modify_glc_in ventory.or iginal.ID[ counter]#"
CFSQLType="CF_SQL_INTEGER" >
</cfquery>
<cfelseif Form.modify_glc_inventory. rowstatus. action[cou nter] is "I">
<cfquery name="InsertNew" datasource="#dbname#" username="#dbuser#" password="#dbpw#">
<!--- Insert handled another way
INSERT into GLC_Inventory (Status_ID, Status_Type)
VALUES (<cfqueryparam
value="#Form.Status_Types. Status_Typ e[counter] #"
CFSQLType="CF_SQL_VARCHAR" >,
<cfqueryparam value="#Form.Status_Types. Status_ID[ counter]#"
CFSQLType="CF_SQL_INTEGER" >) --->
</cfquery>
</cfif>
</cfloop>
</cfif>
When it runs I get an error becuase the columns are not in the right order:
The row action for 1 is: U
BIN = EA <-- this is from unit column
MIN = ACA21 <-- from bin
MAX = 5
Inventory_Count= 5
Inventory_Date= 03/13/2012
Modify = 'bhinshaw',
Modify_Date = '03/13/2012'
How should I code this so that the items are passed to the update in proper order?
Thanks
<cfform name="GridForm" action="update_glc_invento
<cfgrid name="modify_glc_inventory
height=425
autowidth="yes"
width=1020
vspace=10
selectmode="edit"
query="search_query"
insert="No"
delete="No"
format="html"
selectonload = "no"
striperows = "yes"
selectcolor="CDE6F3">
<cfgridcolumn name="ID"
header="ID"
width=40
headeralign="center"
headerbold="Yes"
select="No"
display="No">
<cfgridcolumn name="PID_ID"
header="PID"
width=50
headeralign="center"
headerbold="Yes"
select="No">
<cfgridcolumn name="Description"
header="Description"
width=150
headeralign="center"
headerbold="Yes"
select="No">
<cfgridcolumn name="MOQ"
header="MOQ"
width=30
headeralign="center"
headerbold="Yes"
select="No">
<cfgridcolumn name="COST"
header="Cost"
width=50
headeralign="center"
headerbold="Yes"
select="No">
<cfgridcolumn name="UNIT"
header="Unit"
width=50
headeralign="center"
headerbold="Yes"
select="No">
<cfgridcolumn name="BIN"
header="BIN"
width=50
headeralign="center"
headerbold="Yes"
select="Yes">
<cfgridcolumn name="MIN"
header="MIN"
width=30
headeralign="center"
headerbold="Yes"
select="Yes">
<cfgridcolumn name="MAX"
header="MAX"
width=30
headeralign="center"
headerbold="Yes"
select="Yes">
<cfgridcolumn name="Inventory_Count"
header="Inventory"
width=50
headeralign="center"
headerbold="Yes"
select="Yes">
<cfgridcolumn name="Inventory_Date"
header="Inventory Date"
width=60
headeralign="center"
headerbold="Yes"
select="No"
type="date">
</cfgrid>
<cfinput name="submitit" type="Submit" value="Submit">
</cfform>
I pass that to the update page update_glc_inventory.cfm
<html>
<head>
<title>Catch submitted grid values</title>
</head>
<body>
<h3>Grid values for Form.modify_glc_inventory row updates</h3>
<cfif isdefined("Form.modify_glc
<cfloop index = "counter" from = "1" to =
#arraylen(Form.modify_glc_
<cfoutput>
The row action for #counter# is:
#Form.modify_glc_inventory
<br>
BIN = #Form.modify_glc_inventory
<br>
MIN = #Form.modify_glc_inventory
<br>
MAX = #Form.modify_glc_inventory
<br>
Inventory_Count= #Form.modify_glc_inventory
<br>
Inventory_Date= #dateformat(CreateODBCDate
<br>
Modify = '#getcurruser.uid#',
<br>
Modify_Date = '#dateformat(CreateODBCDat
<br>
</cfoutput>
<cfif Form.modify_glc_inventory.
<cfquery name="DeleteExisting" datasource="#dbname#" username="#dbuser#" password="#dbpw#">
<!--- DELETE FROM GLC_Inventory don't delete just set inactive in case recover needed --->
UPDATE GLC_Inventory
SET ACTIVE_STATUS = 2
WHERE ID=<cfqueryparam
value="#Form.modify_glc_in
CFSQLType="CF_SQL_INTEGER"
</cfquery>
<cfelseif Form.modify_glc_inventory.
<cfquery name="UpdateExisting" datasource="#dbname#" username="#dbuser#" password="#dbpw#">
UPDATE GLC_Inventory
SET
<!------>
<cfif Form.modify_glc_inventory.
BIN=<cfqueryparam
value="#Form.modify_glc_in
CFSQLType="CF_SQL_VARCHAR"
</cfif>
<cfif Form.modify_glc_inventory.
MIN=<cfqueryparam
value="#Form.modify_glc_in
CFSQLType="CF_SQL_INTEGER"
</cfif>
<cfif Form.modify_glc_inventory.
MAX=<cfqueryparam
value="#Form.modify_glc_in
CFSQLType="CF_SQL_INTEGER"
</cfif>
Inventory_Count=<cfquerypa
value="#Form.modify_glc_in
CFSQLType="CF_SQL_INTEGER"
Inventory_Date='#dateforma
<!--- <cfqueryparam
value="#Form.modify_glc_in
CFSQLType="CF_SQL_DATE" >, --->
Modify = '#getcurruser.uid#',
Modify_Date = '#dateformat(CreateODBCDat
WHERE ID=<cfqueryparam
value="#Form.modify_glc_in
CFSQLType="CF_SQL_INTEGER"
</cfquery>
<cfelseif Form.modify_glc_inventory.
<cfquery name="InsertNew" datasource="#dbname#" username="#dbuser#" password="#dbpw#">
<!--- Insert handled another way
INSERT into GLC_Inventory (Status_ID, Status_Type)
VALUES (<cfqueryparam
value="#Form.Status_Types.
CFSQLType="CF_SQL_VARCHAR"
<cfqueryparam value="#Form.Status_Types.
CFSQLType="CF_SQL_INTEGER"
</cfquery>
</cfif>
</cfloop>
</cfif>
When it runs I get an error becuase the columns are not in the right order:
The row action for 1 is: U
BIN = EA <-- this is from unit column
MIN = ACA21 <-- from bin
MAX = 5
Inventory_Count= 5
Inventory_Date= 03/13/2012
Modify = 'bhinshaw',
Modify_Date = '03/13/2012'
How should I code this so that the items are passed to the update in proper order?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Helped me get going in the right direction, Thanks
ASKER
In update_glc_inventory.cfm I added <cfdump var="#form#"> and was able to see it's not skipping, the order of the array is all over the place
http://forums.adobe.com/message/2935249
Not only must the primary key be selectable, any column to the left of a column being edited must also be selectable. So in other words, if you have 6 columns and want column 5 to be editable, the prior four must also be editable.