Skip to main content
January 24, 2012
Question

Form Error: Invalid List Index 0 - help please

  • January 24, 2012
  • 1 reply
  • 8941 views

Inherited this application and I have no expertise with ColdFusion at all...thanks in advance for any suggestions and help!

So, I am getting this error when I chose a person's name from the drop down menu.  I verified they exist in the db.  Here is the full error:

Invalid list index 0.

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

The error occurred in E:\~mld\Forms\inc_Form_Variables.cfm: line 67

65 :           </cfquery>

66 :           <cflock scope="session" timeout="10" type="Exclusive">

67 :                     <cfset session.RelationshipToPatient = ListGetAt(Relationship_To_Patient.PID_RELATIONSHIPLIST,ListFind(Relationship_To_Patient.PID_LIST,PatientToComplete,","),",")><!--- Respondent's relationship to patient --->

68 :           </cflock>

69 : </cfif>

Resources:

Check the ColdFusion documentation to verify that you are using the correct syntax.

Search the Knowledge Base to find a solution to your problem.

Browser            Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7

Remote Address  

Referrer            http://<server Name>/~mld/Nurse/index.cfm?z=0147134&lx=1

Date/Time            24-Jan-12 07:27 AM

Stack Trace

at cfinc_Form_Variables2ecfm1668635045.runPage(E:\~mld\Forms\inc_Form_Variables.cfm:67) at cfForm2ecfm1411423523.runPage(E:\~mld\Nurse\Form.cfm:41)

The referrer above says x=1, so is there something wrong the syntax of line 67?  If you need more info i'd be happy to post more.    I just am so stuck and I need to get this into production and I'm a total noob.  I tried putting in the debug <cfdump var="#form#"> because i used that from a previous issue but this didn't help.  Is there other debug I can use?  thanks!

This topic has been closed for replies.

1 reply

Inspiring
January 24, 2012

Sounds like you might have an empty list.  Is Relationship_To_Patient a query by chance? 

January 24, 2012

Hi Dan,  yes it is.  Thanks for responding.  Here is the block of code:

<!--- Choose new patient --->

<!--- Patient selected on Form.cfm --->

<cfparam name="CP" default="">

<cfif Len(CP)>

    <cflock scope="session" timeout="10" type="Exclusive">

                    <cfset session.PatientToComplete= "">

                    <cfset session.RelationshipToPatient= "">

          </cflock>

   

          <cfif session.UserType is "NURSE"><cflocation url="index.cfm?z=Patients&lx=1" addtoken="No"></cfif>

</cfif>

<cfif Len(PatientToComplete)>

          <cfquery name="Relationship_To_Patient" datasource="#Datasource#" maxrows="1">

                    SELECT                    pid_list,pid_relationshiplist

                    FROM                    registry

                    WHERE                    rid= <cfqueryparam value="#User_temp#" cfsqltype="CF_SQL_VARCHAR" maxlength="5">

                    ORDER BY          registry_id desc

          </cfquery>

          <cflock scope="session" timeout="10" type="Exclusive">

                    <cfset session.RelationshipToPatient = ListGetAt(Relationship_To_Patient.PID_RELATIONSHIPLIST,ListFind(Relationship_To_Patient.PID_LIST,PatientToComplete,","),",")><!--- Respondent's relationship to patient --->

          </cflock>

</cfif>

<!--- Choose new patient --->

BKBK
Community Expert
Community Expert
January 24, 2012

It is clear where the problem comes from. It is from this line:

<cfset session.RelationshipToPatient = ListGetAt(Relationship_To_Patient.PID_RELATIONSHIPLIST,ListFind(Relationship_To_Patient.PID_LIST,PatientToComplete,","),",")>

The error tells us the the value of ListFind(Relationship_To_Patient.PID_LIST,PatientToComplete,",") is 0. In other words, the value PatientToComplete could not be found in Relationship_To_Patient.PID_LIST.

This may be related to the next issue. I see that you've defined 2 similar variables, PatientToComplete and session.PatientToComplete. Shouldn't this be just one variable?