Using CFSEARCH I have the key variable contained as a comma-separate list to return more information than the four custom fields allow. However, the system is throwing an error saying that the list items cannot be found.
Each record of "key" variable will have the following format: a,b,c
<cfsearch
name="theCourses"
collection="#arguments.collectionName#"
type="simple"
startrow="1"
maxrows="100"
criteria="#Lcase(Trim(arguments.searchCriteria))#"
contexthighlightbegin="<b>"
contexthighlightend="</b>"
status="courseListStatus"
/>
<cfset courseList = QueryNew("ID, Score, Course, Subject, Day, Title, Semester, Status", "varchar, varchar, varchar, varchar, varchar, varchar, varchar, varchar") />
<cfloop query="theCourses">
<cfset temp = QueryAddRow(courseList) />
<cfset temp = QuerySetCell(courseList, "ID", custom3) />
<cfset temp = QuerySetCell(courseList, "Score", score) />
<cfset temp = QuerySetCell(courseList, "Course", ListGetAt(key, 2, ",")) />
<cfset temp = QuerySetCell(courseList, "Subject", ListFirst(key, ",")) />
<cfset temp = QuerySetCell(courseList, "Day", custom1) />
<cfset temp = QuerySetCell(courseList, "Title", custom4) />
<cfset temp = QuerySetCell(courseList, "Semester", custom2) />
<cfset temp = QuerySetCell(courseList, "Status", ListLast(key, ",")) />
</cfloop>
I get the following error:
Invalid list index 2.
In function ListGetAt(list, index [, delimiters]), the value of index, 2, is not a valid as the first argument (this list has 1 elements). Valid indexes are in the range 1 through the number of elements in the list.
I’m afraid your assertion that the key will be of the format “a,b,c” is clearly mistaken in this particular case. Otherwise your code would work!
So, as with any “why does this not have the value I expect?” situation, when the thing errors, dump out the value that’s contributing to the error, and eyeball what’s wrong with it.
In this case:
Also: you do not need to set the temp variable on the LHS of that expression if you’re not going to use it (which as it will always be “yes”, I suspect you won’t need. This is fine: