Question
How to insert line item numbers
I have a form where the user enters one or more part numbers,
and a quantity for each part number. When the form is submitted, I
do a cflocation to another page that displays the part number and
then input fields (serial numbers) for each part number, based on
the quantity. For example, of the quantity for part number pn1 is
3, then I dynamically generate three fields to input serial numbers
for that part number.
Here is the code I use :
<td class="TitleText">
<cfoutput query="qrySerialNumbers" group="partNumber"><font face="Verdana" size="2"><b>Part Number:</b> #partNumber#</font><p>
<cfif quantity is 1>
<b>Serial Number:</b><br>
<cfelseif quantity gt 1>
<b>Serial Numbers:</b><br>
</cfif>
<cfloop from="1" to="#quantity#" index="i">
<table border="0">
<tr>
<td width="33" align="right" class="TitleText"><b>#i#:</b> </td>
<td width="148" align="right" clsas="TitleText"><cfinput type="text" name="serialNumber" size="40"><input type="hidden" name="PartNumberID" value="#PartNumberID#"><br></td>
</tr>
This displays the part number once, the title Serial Number or Nubmers, a line item count for each serial number, and the input fields for the serial numbers. So for part number PN1, there are three serial numbers, so it woul have line item #1, serial number input, line item #2, serial number input, line item #3, serial number input. etc...If there is another part number, it skips a line and displays the same info for the next part number, etc.
Here is the problem I am having. The part numbers are stored in one table along with a part number id, and the serial numbers are stored in another table, along with the part number id. I join the two tables together via the part number id to get the part number and its assoicatied serial numbers.When I submit the form, I need to also insert the line items for each serial number. So part number pn1 is inserted into the part number table and the part number id is 1. Serial numbers sn1, sn2, and sn3 are inserted into the serial number table along with part number id 1. The line item numbers inserted should be 1, 2, 3. If there is another part number/serial number, those are also inserted but the line items continue to increment, 4, 5,6..etc. instead of resetting at 1 because it is a new part number.
Here is modfied version of my insert code :
<cfloop from="1" to="#listlen(form.serialNumber)#" index="i">
<cfquery name="qrySerialNumberID" datasource="recDisc">
select max(SerialNumberID) as maxSerialNumberID
from test_SerialNumbers
</cfquery>
<!--- Get the next transaction id by adding 1 to the last number --->
<cfset nextSerialNumberID = #qrySerialNumberID.maxSerialNumberID# + 1>
<cfset col2 = listgetat(form.PartNumberID, i)>
<cfset col3 = listgetat(form.serialNumber, i)>
<cfquery name="qryInsertSerial" datasource="recDisc">
insert into test_SerialNumbers
(serialNumberID,
PartNumberID,
serialNumber,
status,
lineItem,
closedFlag)
values
('#nextSerialNumberID#',
'#col2#',
<cfif col3 is "">
'None',
<cfelse>
'#ucase(col3)#',
</cfif>
'1',
'#i#',
'')
</cfquery>
</cfloop>
Sorry for the long post, had to explain what I am trying to do.
How do I get the line item numbers to reset for each part number ?
Here is the code I use :
<td class="TitleText">
<cfoutput query="qrySerialNumbers" group="partNumber"><font face="Verdana" size="2"><b>Part Number:</b> #partNumber#</font><p>
<cfif quantity is 1>
<b>Serial Number:</b><br>
<cfelseif quantity gt 1>
<b>Serial Numbers:</b><br>
</cfif>
<cfloop from="1" to="#quantity#" index="i">
<table border="0">
<tr>
<td width="33" align="right" class="TitleText"><b>#i#:</b> </td>
<td width="148" align="right" clsas="TitleText"><cfinput type="text" name="serialNumber" size="40"><input type="hidden" name="PartNumberID" value="#PartNumberID#"><br></td>
</tr>
This displays the part number once, the title Serial Number or Nubmers, a line item count for each serial number, and the input fields for the serial numbers. So for part number PN1, there are three serial numbers, so it woul have line item #1, serial number input, line item #2, serial number input, line item #3, serial number input. etc...If there is another part number, it skips a line and displays the same info for the next part number, etc.
Here is the problem I am having. The part numbers are stored in one table along with a part number id, and the serial numbers are stored in another table, along with the part number id. I join the two tables together via the part number id to get the part number and its assoicatied serial numbers.When I submit the form, I need to also insert the line items for each serial number. So part number pn1 is inserted into the part number table and the part number id is 1. Serial numbers sn1, sn2, and sn3 are inserted into the serial number table along with part number id 1. The line item numbers inserted should be 1, 2, 3. If there is another part number/serial number, those are also inserted but the line items continue to increment, 4, 5,6..etc. instead of resetting at 1 because it is a new part number.
Here is modfied version of my insert code :
<cfloop from="1" to="#listlen(form.serialNumber)#" index="i">
<cfquery name="qrySerialNumberID" datasource="recDisc">
select max(SerialNumberID) as maxSerialNumberID
from test_SerialNumbers
</cfquery>
<!--- Get the next transaction id by adding 1 to the last number --->
<cfset nextSerialNumberID = #qrySerialNumberID.maxSerialNumberID# + 1>
<cfset col2 = listgetat(form.PartNumberID, i)>
<cfset col3 = listgetat(form.serialNumber, i)>
<cfquery name="qryInsertSerial" datasource="recDisc">
insert into test_SerialNumbers
(serialNumberID,
PartNumberID,
serialNumber,
status,
lineItem,
closedFlag)
values
('#nextSerialNumberID#',
'#col2#',
<cfif col3 is "">
'None',
<cfelse>
'#ucase(col3)#',
</cfif>
'1',
'#i#',
'')
</cfquery>
</cfloop>
Sorry for the long post, had to explain what I am trying to do.
How do I get the line item numbers to reset for each part number ?
