6 Replies Latest reply on Dec 22, 2009 9:20 AM by Enigma Rose

    Problem updating db table from an array

    Enigma Rose

      I get this error when running this query from a custom tag using this array:

      Element 13 is undefined in a CFML structure referenced as part of an expression.

       

       

      Query:

      <cfif mode is "update" and type is "request">
           <cfdump var="#session.aDelgtRR#" />    
           <cftry>
          <cfloop List="#ArrayLen(session.aDelgtRR)#" index="x">       
              <cfloop List="#ArrayLen(session.aDelgtRR[x].session.AreaID)#" index="y">
                  <!--- 12/18/09 nothing I've tried works. Still get undefined error in cfcatch
                  <cfif NOT ArrayIsEmpty(session.aDelgtRR[#x#].session.AreaID)> --->
                 
                  <cfloop List="#ArrayLen(session.aDelgtRR[x].session.AreaID[y].session.JobRole)#" index="z">       
                             
                         
                          <cfquery name="qUpUserRemove_Rqst" datasource="#request.at_datasource#">
                              UPDATE JOB_DelgtAreaRole
                              Set RemoveType=<cfqueryparam value="#session.aDelgtRR[x].session.RemoveType[x]#" cfsqltype="CF_SQL_VARCHAR" />,
                              RemoveRqstStat=<cfqueryparam value="SUBMITTED" cfsqltype="CF_SQL_VARCHAR" />,
                              Updated=<cfqueryparam value="#now()#" cfsqltype="CF_SQL_TIMESTAMP" />,
                              WhoUpdated=<cfqueryparam value="#IHSUID#" cfsqltype="CF_SQL_INT" />
                              WHERE IHSUID = <cfqueryparam value="#session.aDelgtRR[x].session.DelgtID#" cfsqltype="CF_SQL_INT" />
                              and IHSAreaAssignedID = <cfqueryparam value="#session.aDelgtRR[x][y]#" cfsqltype="CF_SQL_SMALLINT" />               
                              and fk_JobUser_Role = <cfqueryparam value="#session.aDelgtRR[x][y].session.JobRole[z]#" cfsqltype="CF_SQL_SMALLINT" /> 
                          </cfquery>       
                      
                  </cfloop>
              <!---     <cfelse>
                  </cfif> --->
              </cfloop>
          </cfloop>
                 <cfcatch type="coldfusion.runtime.UndefinedElementException"><cfdump var="Undefined error" /></cfcatch>         
                    <cfcatch type="coldfusion.runtime.CfJspPage$ArrayBoundException"><cfdump var="Array Bound error" /></cfcatch>
                </cftry>
      </cfif>
      <cfcatch type="Any">
          <cftransaction action="rollback" />
      <cfset ArrayAppend(session.serror,"Your submission has encountered an error.") />
      </cfcatch>
      </cftry>
      </cftransaction>

       

      array
      1
      struct
      SESSION
      struct
      AREAID
      array
      1
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      2
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      3
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      4
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      5
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      6
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      7
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      8
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      9
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      10
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      11
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      12
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      13
      struct
      SESSION
      struct
      JOBROLE
      array
      15
      27
      DELGTID8074
      REMOVETYPE
      struct
      1Remove Role
      2
      struct
      SESSION
      struct
      AREAID
      array
      1
      struct
      SESSION
      struct
      JOBROLE
      array
      16
      24
      2
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      3
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      4
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      5
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      6
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      7
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      8
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      9
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      10
      struct
      SESSION
      struct
      JOBROLE
      array
      14
      23
      11
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      12
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      13
      struct
      SESSION
      struct
      JOBROLE
      array  [empty]
      DELGTID14599
      REMOVETYPE
      struct
      2Remove Role

       


        • 1. Re: Problem updating db table from an array
          Dan Bracuk Level 5

          To start, you have this:

          <cfloop List="#ArrayLen(session.aDelgtRR)#" index="x">       
                  <cfloop List="#ArrayLen(session.aDelgtRR[x].session.AreaID)#" index="y">

           

          Just for fun, do this:

           

          <cfldump var ="#ArrayLen(session.aDelgtRR)#">       
          <cfcump var="#ArrayLen(session.aDelgtRR[x].session.AreaID)#">
          <cfabort>

           

          Are there any similarities between what you see and what you expected to see?

          • 2. Re: Problem updating db table from an array
            Enigma Rose Level 1

            I did this:

             

            <cfloop List="#ArrayLen(session.aDelgtRR)#" index="x">       
                    <cfloop List="#ArrayLen(session.aDelgtRR[x].session.AreaID)#" index="y">
                    aDegtRR length: <cfdump var="#ArrayLen(session.aDelgtRR)#">
                aDegtRR Area ID length: <cfdump var="#ArrayLen(session.aDelgtRR[x].session.AreaID)#">
                    <cfabort />

             

            And got this:

             

            aDegtRR length:2 aDegtRR Area ID length:13

             

            AreaID length should be 13 for each aDelgtRR length.

             

            Then I did this:

             

            <cfloop List="#ArrayLen(session.aDelgtRR)#" index="x">       
                    <cfloop List="#ArrayLen(session.aDelgtRR[x].session.AreaID)#" index="y">

                      <cfloop List="#ArrayLen(session.aDelgtRR[x].session.AreaID[y].session.JobRole)#" index="z">       
                            aDegtRR length: <cfdump var="#ArrayLen(session.aDelgtRR)#">
                            aDegtRR Area ID length: <cfdump var="#ArrayLen(session.aDelgtRR[x].session.AreaID)#">
                            aDegtRR Area ID Job Role length: <cfdump var="#ArrayLen(session.aDelgtRR[x].session.AreaID[y].session.JobRole)#">

             

            And got this:

            aDegtRR length:2 aDegtRR Area ID length:13 aDegtRR Area ID Job Role length:0Undefined error

            • 3. Re: Problem updating db table from an array
              Dan Bracuk Level 5

              You're making progress.  If this:  aDegtRR length: <cfdump var="#ArrayLen(session.aDelgtRR)#">
              gives you this:  aDegtRR length: 13

              It tells you that the array has 13 elements.  So far, so good.

               

              Then if you do this:

              <cfloop List="#ArrayLen(session.aDelgtRR)#" index="x"> 

              <cfdump var="x is #x#"><br>

              </cloop>

               

              Do you see what you expected to see?

              • 4. Re: Problem updating db table from an array
                Enigma Rose Level 1

                I so appreciate you helping me out !!

                 

                I didn't get what you indicated.

                 

                There are 2 delgts. Each delgt will have 13 areas. Only some areas will have job roles.

                This give me a length of 2:  aDegtRR length:

                This give me a length of 13:  aDegtRR Area ID length: <cfdump var="#ArrayLen(session.aDelgtRR[x].session.AreaID)#"

                • 5. Re: Problem updating db table from an array
                  Dan Bracuk Level 5

                  Maybe this will make it more clear.  From what you said, ArrayLen(session.aDelgtRR) is 2, and ArrayLen(session.aDelgtRR[x].session.AreaID) is 13.  The code below is a simplified version of your OP.  Look at it and try to figure out what you would see if you run it.  Then run it and see if your were right.

                   

                  <cfoutput>

                  <cfloop List="#ArrayLen(session.aDelgtRR)#" index="x">

                  x is #x# <br>

                  <cfloop List="#ArrayLen(session.aDelgtRR[x].session.AreaID)#" index="y">

                  y is #y# <br>

                  </cfloop>

                  </cfloop>

                  <hr>

                  </cfoutput>

                  • 6. Re: Problem updating db table from an array
                    Enigma Rose Level 1

                    I got what I expected:

                    x is 2

                    y is 13

                     

                    In the first pass through the array, Delgtid 8074, element 13 is the only one that actually has job roles.

                    The second pass, for Delgtid 14599, has jobroles for area 1 and 10, but does not have any job roles for element 13.

                     

                    Thanks for your help, Dan.