7 Replies Latest reply on Nov 3, 2009 4:26 AM by djkhalif

    listGetAt error

    djkhalif Level 1

      Good morning all,

       

      I am using this code:

       

      <cfif listlen(list1) gt 0>
      Units:
      <cfloop from="1" to="#listlen(list1)#" index="j">
      <cfoutput>#listGetAt(list1, j)# </cfoutput>
      </cfloop>
      <br />
      Defect Codes:
      <cfloop from="1" to="#listlen(list2)#" index="k">
      <cfoutput>#listGetAt(list2, k)#</cfoutput>
      </cfloop>
      </cfif>

       

      I keep getting this error:

       

      In function ListGetAt(list, index [, delimiters]), the value of index, 6, is not a valid as the first argument (this list has 5 elements). Valid indexes are in the range 1 through the number of elements in the list.

       

       

      Has anyone resolved this issue?

       

      Thanks in advance,

       

      DJ Khalif

        • 1. Re: listGetAt error
          Dan Bracuk Level 5

          This would be more reliable, also faster.

           

          <cfif listlen(list1) gt 0>
          Units:
          <cfloop list="#List1#" index = "abc">
          <cfoutput>#abc# </cfoutput>
          </cfloop>

           

          To troubleshoot your current code, start displaying data.

           

          <cfif listlen(list1) gt 0>

          <cfdump var = "List 1 is #list1#>

          <cfflush>
          Units:
          <cfloop from="1" to="#listlen(list1)#" index="j">
          <cfoutput>j is #j# list item is  #listGetAt(list1, j)# </cfoutput>

          <cfflush>
          </cfloop>
          <br />
          and something similar for your other list.

          • 2. Re: listGetAt error
            djkhalif Level 1

            Dan,

             

            Thanks, I used this:

             

            <cfif listlen(list1) gt 0>
            Units:
            <cfloop list ="#list1#" index="j">
            <cfoutput>#j# </cfoutput>
            </cfloop>
            </cfif>
            <br />
            <cfif listlen(list2) gt 0>
            Defect Codes:
            <cfloop list ="#list2#" index="k" >
            <cfoutput>#k#</cfoutput>
            </cfloop>
            </cfif>

             

            Now, can you make sense out of this:

             

            <cfquery name="finalDefects" datasource="#REQUEST.datasource#">
            INSERT INTO tbl_Final_Defects (ID, Unit, DefectCode)
            SELECT ID, '#Trim(FORM.Unit)#', '#Trim(FORM.DefectCode)#'
            FROM tbl_FinalInspAttr
            WHERE tbl_FinalInspAttr.WorkOrder = '#FORM.WorkOrder#' and 1 = 2
            <cfloop list="#FORM.UNIT#" index="j" >
            UNION
            SELECT DISTINCT #Trim(FORM.UNIT)#, '#j#'
            FROM tbl_DefectTypes
            </cfloop>
            </cfquery>

             

             

            How can I get both list to populate the database?

            • 3. Re: listGetAt error
              Dan Bracuk Level 5

              If the two lists are the same length, a from, to loop in your query is the way to go.  Couple of notes though:

               

              In union queries you don't need the keyword distinct.

              Your current query is not getting the ID value you want.   What's the logic you intended to use to get that?

              • 4. Re: listGetAt error
                djkhalif Level 1

                Dan,

                 

                 

                The two lists are unequal. For example, units 1, 7,16,25 and 28 can have the same defect code 1 therefore, when the user enters data into the main form then the ID from the main form should match be the ID for those records Ex.:

                 

                                    (list1)               (list2)

                ID               Unit               Defect Code

                 

                 

                2345               1                    1

                2345               7                    1

                2345               16                  1

                2345               25                  1

                2345               28                  1

                 

                Main Table

                 

                 

                ID                WorkOrder

                 

                 

                2345            ####### and so on and so forth.

                 

                 

                Thanks,

                 

                djkhalif

                • 5. Re: listGetAt error
                  Dan Bracuk Level 5

                  What do you have in place to determine what defect goes with each unit?

                  • 6. Re: listGetAt error
                    djkhalif Level 1

                    Dan,

                     

                    I mirrored the exisiting VB process to dump into Access but utilized CF8 and SQL. The user will have to enter the Unit(s) per defect. There is one defect per unit that is recorded. The problem will be, if the unit has mulitple defects. I needed to get something in place where I can go back and repair. This worked:

                     

                    <cfset list1 = #FORM.Unit# >
                    <cfset list2 = #FORM.DefectCode#>
                    <cfloop list="#list1#" index="j">
                    <cfloop list="#list2#" index="k">
                    <cfquery name="finalDefects" datasource="#REQUEST.datasource#">
                    INSERT INTO tbl_Final_Defects(ID, Unit, DefectCode)
                    SELECT ID, '#Trim(j)#', '#Trim(k)#'
                    FROM tbl_FinalInspAttr
                    WHERE WorkOrder = '#FORM.WorkOrder#'
                    </cfquery>
                    </cfloop>
                    </cfloop>

                     

                    My id match but, I think it entered in my unit/defectcode table twice. This I will monitor. For now, its accepting data.

                     

                     

                    Thanks,

                     

                    DJ Khalif

                    • 7. Re: listGetAt error
                      djkhalif Level 1

                      Dan,

                       

                      Thanks for your responses and answers. That was a BIG help.

                       

                       

                      Thanks,

                       

                      DJ Khalif