Copy link to clipboard
Copied
Hello,
I have migrated our Coldfusion apps from a server running ColdFusion 11 to 21, most have been successful but I am having difficulty resolving one error and would appreciate if anybody has any advice.
The block that errors is:
<CFLOOP INDEX="i" FROM="1" TO="#listlen(Form.Net)#">
<CFSET #Net# = #listgetat(Form.Net,i,",","true")#>
<CFSET #vat# = #listgetat(Form.vat,i,",","true")#>
<CFSET #Dep# = #listgetat(Form.dep,i,",","true")#>
<cfif #len(Dep)# eq "0">
<cfset #Dep# ="XX">
</cfif>
<CFSET #Act# = #listgetat(Form.act,i,",","true")#>
<cfif #len(Act)# eq "0">
<cfset #Act# ="Null">
</cfif>
<CFSET #Prj# = #listgetat(Form.prj,i,",","true")#>
<cfif #len(prj)# eq "0">
<cfset #prj# ="Null">
</cfif>
<CFSET #Loc# = #listgetat(Form.loc,i,",","true")#>
<cfif #len(loc)# eq "0">
<cfset #loc# ="">
</cfif>
<CFSET #PO# = #listgetat(Form.po,i,",","true")#>
<cfif #len(PO)# eq "0">
<cfset #PO# =#variables.MaxPO#>
</cfif>
<CFSET #LineDescr# = #listgetat(Form.LineDescr,i,",","true")#>
<cfif #len(LineDescr)# eq "0">
<cfset #LineDescr# ="XXXX">
</cfif>
I am new to ColdFusion and picking up somebody else's code so I am not 100% sure where the issue lies but the from research it may be the change in CFLOOP's behaviour in the 2016 release?
This is how the data is input-
The user should be able to input as many lines as nessecary, but should only have to populate Dep, Project etc on the first line, and it should be copied for all subsequent lines, only Net and VAT should be required for every line. This works as expected on CF11.
The CF21 page works for single lines but errors when more than one line is entered. The error code is as follows:
Mar 28, 2023 15:33:55 PM Error [ajp-nio-127.0.0.1-8020-exec-15] - 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. The specific sequence of files included or processed is: "path", line: 243
<CFSET #Dep# = #listgetat(Form.dep,i,",","true")#> is line 243.
The code works as expected on the old ColdFusion 11 server and only errors on the new server, has anybody had a similar issue before?
Any advice or guidance would be greatly appreciated.
I have refactored the above solution. Here's the result:
<!--- The idea is to list-append the empty string, where necessary, to make sure each list has the same length --->
<!--- Get the length of each list. The lists may not be of equal length. We will have to pad shorter lists up by appending empty string list elements. --->
<cfset NetListLength=listlen(Form.Net, ',', true)>
<cfset vatlistLength = listLen(Form.vat,",","true")>
<cfset DeplistLength = listLen(Form.dep,",","true")>
<cfset Ac
...
Copy link to clipboard
Copied
The last error you received suggests you might be close to a solution. Let me explain.
Perhaps the following form behaves differently in cf11 and cf2021. That is, perhaps the list length is 5 in CF11, but 2 in cf2021.
<!--- Compare on CF11 and CF2021 (Test with sameFormFieldsAsArray="false")--->
<cfif isdefined('form.x')>
<cfoutput>List length = #listlen(form.x,',',true)#</cfoutput>
</cfif>
<cfform >
<cfinput name="x" value="1" >
<cfinput name="x" value="2" >
<cfinput name="x" value="" >
<cfinput name="x" value="" >
<cfinput name="x" value="" >
<cfinput name="sbmt" value="send" type="submit" >
</cfform>
Copy link to clipboard
Copied
Any joy?