Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array to List.. then Loop and Update (another CF rookie)

Status
Not open for further replies.

CFDev

Programmer
Joined
Aug 24, 2001
Messages
8
Location
US


I have a data entry page which allows the user to either update or bypass actl_perf_amt. This, and a number of other hidden fields, are then passed to an UpdatePerf (Action Page) in a comma delimited list. I first use the ListContains to cull out any bypasses (BypassMthCheck). I then want to save ALL changes with one submit. When I try to update I get the following error message:



An error occurred while evaluating the expression:
msur_actl_perf_amt = #ListGetAt(form.actl_perf_amt, ListRead, ",")#
Error near line 18, column 8.

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

My action page is as follows:

<CFTRANSACTION>
<CFLOOP Index=&quot;ListRead&quot;
From =&quot;1&quot; To=&quot;#FormrecCount#&quot;>

<CFIF NOT parameterExists (BypassMthCheck)>
<CFSET ignore_month = &quot;N&quot;>
<CFSET msur_actl_perf_amt = #ListGetAt(form.actl_perf_amt, ListRead, &quot;,&quot;)#>

<CFELSEIF ListContains(BypassMthCheck, ListRead, &quot;,&quot;) IS 0>

<CFSET ignore_month = &quot;N&quot;>
<CFSET msur_actl_perf_amt = #ListGetAt(form.actl_perf_amt, ListRead, &quot;,&quot;)#>
<CFELSE>
<CFSET ignore_month = &quot;Y&quot;>
<CFSET msur_actl_perf_amt = 0>
</CFIF>



<CFSET actl_perf_amt = #ListGetAt(form.msur_actl_perf_amt, ListRead, &quot;,&quot;)#>>


<CFIF #GetPerf.RecordCount# IS 0>
<CFQUERY NAME=&quot;InsertPerf&quot; DATASOURCE=&quot;PGM&quot;>
INSERT INTO Performance(perf_date, actl_perf_amt…)
VALUES (#ODBCSelectedDate#, #msur_actl_perf_amt#…')
</CFQUERY>
<CFELSE>
<CFQUERY NAME=&quot;UpdtPerf&quot; DATASOURCE=&quot;PGM&quot;>
UPDATE Performance
SET ignore_month = '#ignore_month#',
actl_perf_amt = #msur_actl_perf_amt#
WHERE ….
</CFQUERY>
</CFIF>



</CFQUERY>
</CFLOOP>
</CFTRANSACTION>

<CFINCLUDE TEMPLATE=&quot;UpdateDetail.cfm&quot;>



 
the list (form.actl_perf_amt) has only one element; try breaking the execution of the code, use this:

<cfoutput>#form.actl_perf_amt#</cfoutput>
<cfexit>

find out exactly what is the value of &quot;form.actl_perf_amt&quot; list and why it has only one element;
Note:
ColdFusion ignores empty list elements; thus, a list that is defined as &quot;a,b,c,,,d&quot; is treated as a four element list.
Sylvano
dsylvano@hotmail.com
 
Thanks Sylvano:-)

The 9 data records are entered as follows:
8.67, B, 25.00, B, B, 96.00, B, B, B
(B=Bypass Record which produces .0000)

Code test returns 8.67,25.00,96.00 so it is bypassing the appropriate records but should the comma delimited list look like 8.67,25.00,,96.00,,, ????

What now? I'm completely stumped on this one and any help is greatly appreciated!

Donna Hodgson
Systems Analyst
 
CF ignores empty list elements, the return is fine (,, values are ignored); I think that the simplest way for you to solve the problem you have is that you asign default value to the form fields to ensure that list have no empty list elements;
you have one or two typos in your code; try using this instead:


<CFTRANSACTION>
<CFLOOP Index=&quot;ListRead&quot; From =&quot;1&quot; To=&quot;#FormrecCount#&quot;>

<CFIF NOT parameterExists(BypassMthCheck) OR ListContains(BypassMthCheck, ListRead, &quot;,&quot;) IS 0>
<CFSET ignore_month = &quot;N&quot;>
<CFELSE>
<CFSET ignore_month = &quot;Y&quot;>
<CFSET msur_actl_perf_amt = 0>
</CFIF>

<CFSET msur_actl_perf_amt = ListGetAt(form.actl_perf_amt, ListRead, &quot;,&quot;)>

<CFSET actl_perf_amt = ListGetAt(form.msur_actl_perf_amt, ListRead, &quot;,&quot;)>


<CFIF GetPerf.RecordCount IS 0>
<CFQUERY NAME=&quot;InsertPerf&quot; DATASOURCE=&quot;PGM&quot;>
INSERT INTO Performance(perf_date, actl_perf_amt…)
VALUES (#ODBCSelectedDate#, '#msur_actl_perf_amt#')
</CFQUERY>
<CFELSE>
<CFQUERY NAME=&quot;UpdtPerf&quot; DATASOURCE=&quot;PGM&quot;>
UPDATE Performance
SET ignore_month = '#ignore_month#',
actl_perf_amt = '#msur_actl_perf_amt#'
WHERE ….
</CFQUERY>
</CFIF>



</CFQUERY>
</CFLOOP>
</CFTRANSACTION>


Sylvano
dsylvano@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top