• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

listGetAt error

Participant ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

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

TOPICS
Advanced techniques

Views

2.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 03, 2009 Nov 03, 2009

Copy link to clipboard

Copied

LATEST

Dan,

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

Thanks,

DJ Khalif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation