0 Replies Latest reply on Apr 16, 2010 2:11 PM by stuttsdc

    cfgrid update and insert issue *help!!*

    stuttsdc Level 1

      I have a form that contains a cfgrid named idGrid (using CF9). 
      Contains  four columns: Autonum (for now, the pk), CR_ID (fk), ID, and IDType.
      These  come from tblIDs in my db.

      The grid is editable but not the  Autonum or CR_ID fields (select="no").

      I am using code straight  from the Adobe help:
      http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24 -7acf.html

      If  I try to edit the existing records in this grid, it posts back values  into the wrong columns!  It puts the CR_ID into tblIDs.ID and the ID  into tblIDs.IDType.

      If I try to insert a new record and then post  back the changes, I get an error:
      Element IDGGRID.ROWSTATUS.ACTION  is undefined in a Java object of type class [Ljava.lang.String;  referenced as ''

      I believe this is b/c fields in the new  record are null.  Autonum and CR_ID would likely be null but the user  might also just not enter anything. 
      Major problem and I don't know  how to get around it.

      Please help!
      ---

      <cfquery name="get_IDs" datasource="bridges">
      SELECT tblIDs.Autonum, tblIDs.CR_ID, tblIDs.ID, tblIDs.IDType
      FROM tblIDs
      WHERE tblIDs.CR_ID = '#CFGRIDKEY#'
      </cfquery>

      <cfgrid
              name="idGrid"
              title="Related IDs"
              width="250" rowheaderalign="left"    
              query="get_IDs"
              autowidth="false" griddataalign="left" gridlines="yes" colheaderalign="left"
              selectmode="edit" insert="yes" insertbutton="Insert New ID" enabled="yes" visible="yes"
              format="html">

            <cfgridcolumn name="Autonum" display="no" select="no"/>
            <cfgridcolumn name="CR_ID" display="no" select="no"/>
            <cfgridcolumn name="ID" header="ID" />
            <cfgridcolumn name="IDType" header="ID Source" values="#r_idType#" valuesdisplay="#r_idType#" valuesdelimiter=","/>
          </cfgrid>

      form posts to:

      <cfloop index = "counter" from = "1" to =
              #arraylen(Form.idGrid.rowstatus.action)#>

             
               <cfoutput>
                  The row action for #counter# is:
                  #Form.idGrid.Autonum[counter]#
                  #Form.idGrid.CR_ID[counter]#
                  #Form.idGrid.ID[counter]#
                  #Form.idGrid.IDType[counter]#
                  <br>
              </cfoutput>

      [b]<!-- Here, if updating and not inserting, it'll give back results like: The row action for 1 is: 11093 11093 {666666666666JUNKME} onceagain.  It's showing the Autonum field twice!! -->[/b]

              <cfif Form.idGrid.rowstatus.action[counter] is "U">
                  <cfquery name="UpdateIDTable"
                      datasource="bridges">

                      UPDATE tblIDs
                      SET 
                          ID=<cfqueryparam 
                                  value="#Form.idGrid.ID[counter]#" 
                                  CFSQLType="CF_SQL_VARCHAR" >
      ,
                          IDType=<cfqueryparam 
                                  value="#Form.idGrid.IDType[counter]#" 
                                  CFSQLType="CF_SQL_VARCHAR" >

                      WHERE Autonum=<cfqueryparam
                          value="#Form.idGrid.original.Autonum[counter]#" 
                          CFSQLType="CF_SQL_INTEGER">

                  </cfquery>

              <cfelseif Form.idGgrid.rowstatus.action[counter] is "I">
                  <cfquery name="InsertNewID"
                      datasource="bridges">

                      INSERT into tblIDs (CR_ID, ID, IDType)
                      VALUES (<cfqueryparam 
                          value="#Form.i_cr_id#"  [i](id taken from elsewhere)[/i]
                                  CFSQLType="CF_SQL_VARCHAR" >
      ,
                              <cfqueryparam value="#Form.idGrid.ID[counter]#" 
                                  CFSQLType="CF_SQL_VARCHAR" >
      ,
                              <cfqueryparam value="#Form.idGrid.IDType[counter]#" 
                                  CFSQLType="CF_SQL_VARCHAR" >
        )
                  </cfquery>

      ALSO... same things happens if I just use cfgridupdate:
      <cfgridupdate grid = "idGrid" dataSource = "bridges" Keyonly="true"
              tableName = "tblIDs">

              </cfif>
          </cfloop>
      </cfif>