Skip to main content
Inspiring
November 2, 2009
Question

listGetAt error

  • November 2, 2009
  • 1 reply
  • 2591 views

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

This topic has been closed for replies.

1 reply

Inspiring
November 2, 2009

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.

djkhalifAuthor
Inspiring
November 2, 2009

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?

djkhalifAuthor
Inspiring
November 2, 2009

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


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