displaying previously entered multiple fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bonneylake
    Contributor
    • Aug 2008
    • 769

    Originally posted by acoder
    Yes, the delete would go at the bottom.

    You don't need the inner loop in the first one any more (line 10-18 in 2nd code block). Neither do you need currSerialNum anywhere.

    For the array, you just need the actual serial number values, not "serialnum = ...".
    Hey Acoder,

    So for the delete what would i change the condition to because i have the following right now

    Code:
    <cfloop condition="currSerialNo neq countserials.pka_serialNo">
    <CFSET serialnum       = Form["serialnum_" & machineCount]>
    <cfquery name="deleteserialparts" datasource="CustomerSupport">
    exec usp_CS_Deleteserialparts   
    <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
    '#Form.pk_ticketID#'
    </cfquery>
    </cfloop>
    an so for the array for each one this would be ok?

    Code:
      <CFSET ArrayAppend(test, "Form["serialnum_" & machineCount]")>
    Thank you,
    Rach

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      Yes, there's no need for a condition any longer because you'll be looping over the query.

      In the array, you need to wrap the form value in #s.

      Comment

      • bonneylake
        Contributor
        • Aug 2008
        • 769

        Originally posted by acoder
        Yes, there's no need for a condition any longer because you'll be looping over the query.

        In the array, you need to wrap the form value in #s.
        Hey Acoder,

        so would this be correct for the delete at the bottom?

        Code:
        <cfloop query="countserials">
        <CFSET serialnum       = Form["serialnum_" & machineCount]>
        <cfquery name="deleteserialparts" datasource="CustomerSupport">
        exec usp_CS_Deleteserialparts   
        <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
        '#Form.pk_ticketID#'
        </cfquery>
        </cfloop>
        and then for the array this correct?

        Code:
          <CFSET ArrayAppend(test, "#Form["serialnum_" & machineCount]#")>
        Thank you,
        Rach

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          The array should be correct. You can cfdump to make sure.

          In the delete loop, set serialnum to the field name or you can use the serialNo field name itself. Then you need to compare against the contents of the array. Unfortunately, Coldfusion doesn't have an ArrayFind, but you could use a UDF from CFLib for example, or convert the array to a list and then use ListFind().

          Comment

          • bonneylake
            Contributor
            • Aug 2008
            • 769

            Originally posted by acoder
            The array should be correct. You can cfdump to make sure.

            In the delete loop, set serialnum to the field name or you can use the serialNo field name itself. Then you need to compare against the contents of the array. Unfortunately, Coldfusion doesn't have an ArrayFind, but you could use a UDF from CFLib for example, or convert the array to a list and then use ListFind().
            Hey Acoder,

            are you saying something like this for the delete loop?

            Code:
            <cfloop query="countserials">
            <CFSET serialnum = #Form.serialnum#>
            <cfquery name="deleteserialparts" datasource="CustomerSupport">
            exec usp_CS_Deleteserialparts   
            <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
            '#Form.pk_ticketID#'
            </cfquery>
            </cfloop>
            an for the array would this convert it ?

            Code:
            <cfset test = ArrayNew(1)>
              <CFSET ArrayAppend(test, "#Form["serialnum_" & machineCount]#")>
              <CFSET ArrayAppend(test, "#Form["modelno_" & machineCount]#")>
              <CFSET ArrayAppend(test, "#Form["producttype_" & machineCount]#")>
              <CFSET ArrayAppend(test, "#Form["softhardware_" & machineCount]#")>
              <CFSET ArrayAppend(test, "#Form["resolution_" & machineCount]#")>
              <CFSET ArrayAppend(test, "#Form["resdate_" & machineCount]#")>
              <CFSET ArrayAppend(test, "#Form["resvertified_" & machineCount]#")>
              <CFSET ArrayAppend(test, "#Form["vertifidate_" & machineCount]#")>
              <CFSET ArrayAppend(test, "#Form["deptvendor_" & machinecount]#")>
              <CFSET ArrayAppend(test, "#Form["hardwarefailure_" & machineCount]#")>
              <CFSET ArrayAppend(test, "#Form["thedescription_" & machineCount]#")>
              <cfset myList = ArrayToList(test, ",")>
              <cfset anothert = ListFind(myList, form.serialnum)>
            Thank you,
            Rach

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              In the delete loop, the serial number should be the field from the query, not a form field.

              In the array, you only need the serial numbers for comparison, not all the fields.

              Comment

              • bonneylake
                Contributor
                • Aug 2008
                • 769

                Originally posted by acoder
                In the delete loop, the serial number should be the field from the query, not a form field.

                In the array, you only need the serial numbers for comparison, not all the fields.
                Hey Acoder,

                so for the delete loop it should be like so

                Code:
                <cfloop query="countserials">
                <CFSET serialnum = <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">>
                <cfquery name="deleteserialparts" datasource="CustomerSupport">
                exec usp_CS_Deleteserialparts   
                <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                '#Form.pk_ticketID#'
                </cfquery>
                an for the array i am confused are you meaning something like this

                Code:
                <cfset test = ArrayNew(1)>
                  <CFSET ArrayAppend(test, "#Form["serialnum_" & machineCount]#")>
                  <CFSET ArrayAppend(test, "#Form["modelno_" & machineCount]#")>
                  <CFSET ArrayAppend(test, "#Form["producttype_" & machineCount]#")>
                  <CFSET ArrayAppend(test, "#Form["softhardware_" & machineCount]#")>
                  <CFSET ArrayAppend(test, "#Form["resolution_" & machineCount]#")>
                  <CFSET ArrayAppend(test, "#Form["resdate_" & machineCount]#")>
                  <CFSET ArrayAppend(test, "#Form["resvertified_" & machineCount]#")>
                  <CFSET ArrayAppend(test, "#Form["vertifidate_" & machineCount]#")>
                  <CFSET ArrayAppend(test, "#Form["deptvendor_" & machinecount]#")>
                  <CFSET ArrayAppend(test, "#Form["hardwarefailure_" & machineCount]#")>
                  <CFSET ArrayAppend(test, "#Form["thedescription_" & machineCount]#")>
                  <cfset myList = ArrayToList(test, ",")>
                  <cfset anothert = ListFind(form.serialnum)>
                Thank you,
                Rach

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  Originally posted by bonneylake
                  so for the delete loop it should be like so
                  Not quite. cfqueryparam is only required inside a cfquery tag. You only need the field name which would be pka_serialNo in this case.
                  Originally posted by bonneylake
                  an for the array i am confused are you meaning something like this
                  No. You only need the serial number, so only lines 1-2 and 13-14 - the rest of the lines are not needed because the array is only for comparison and the only value you're comparing against is the serial number.

                  Comment

                  • bonneylake
                    Contributor
                    • Aug 2008
                    • 769

                    Originally posted by acoder
                    Not quite. cfqueryparam is only required inside a cfquery tag. You only need the field name which would be pka_serialNo in this case.
                    No. You only need the serial number, so only lines 1-2 and 13-14 - the rest of the lines are not needed because the array is only for comparison and the only value you're comparing against is the serial number.
                    Hey Acoder,

                    Alrighty here is what i have for the delete

                    Code:
                    <cfloop query="countserials">
                    <CFSET serialnum = #pka_serialNo#>
                    <cfquery name="deleteserialparts" datasource="CustomerSupport">
                    exec usp_CS_Deleteserialparts   
                    <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                    '#Form.pk_ticketID#'
                    </cfquery>
                    </cfloop>
                     </CFIF>
                    and here is what i have for the first loop

                    Code:
                    <cfset test = ArrayNew(1)>
                      <CFSET ArrayAppend(test, "#Form["serialnum_" & machineCount]#")> 
                      <cfset myList = ArrayToList(test, ",")>
                      <cfset anothert = ListFind(form.serialnum)>
                    but i was wondering what do i need to do with the rest of the fields, these ones because we had original had them an it was just cfset modelno = #Form["modelno_" * machineCount]#>

                    Code:
                      <CFSET ArrayAppend(test, "#Form["modelno_" & machineCount]#")>
                      <CFSET ArrayAppend(test, "#Form["producttype_" & machineCount]#")>
                      <CFSET ArrayAppend(test, "#Form["softhardware_" & machineCount]#")>
                      <CFSET ArrayAppend(test, "#Form["resolution_" & machineCount]#")>
                      <CFSET ArrayAppend(test, "#Form["resdate_" & machineCount]#")>
                      <CFSET ArrayAppend(test, "#Form["resvertified_" & machineCount]#")>
                      <CFSET ArrayAppend(test, "#Form["vertifidate_" & machineCount]#")>
                      <CFSET ArrayAppend(test, "#Form["deptvendor_" & machinecount]#")>
                      <CFSET ArrayAppend(test, "#Form["hardwarefailure_" & machineCount]#")>
                      <CFSET ArrayAppend(test, "#Form["thedescription_" & machineCount]#")>
                    Thank you,
                    Rach

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      The array is not meant to replace the cfset lines. Those lines have to stay and the array code is in addition to the previous code, not replace it because they are for different purposes.

                      Comment

                      • bonneylake
                        Contributor
                        • Aug 2008
                        • 769

                        Originally posted by acoder
                        The array is not meant to replace the cfset lines. Those lines have to stay and the array code is in addition to the previous code, not replace it because they are for different purposes.
                        Hey Acoder,

                        so our you saying to do it like below?

                        Code:
                        <cfset test = ArrayNew(1)>
                          <CFSET ArrayAppend(test, "#Form["serialnum_" & machineCount]#")> 
                          <CFSET ArrayAppend(test, "#Form["modelno_" & machineCount]#")>
                          <CFSET ArrayAppend(test, "#Form["producttype_" & machineCount]#")>
                          <CFSET ArrayAppend(test, "#Form["softhardware_" & machineCount]#")>
                          <CFSET ArrayAppend(test, "#Form["resolution_" & machineCount]#")>
                          <CFSET ArrayAppend(test, "#Form["resdate_" & machineCount]#")>
                          <CFSET ArrayAppend(test, "#Form["resvertified_" & machineCount]#")>
                          <CFSET ArrayAppend(test, "#Form["vertifidate_" & machineCount]#")>
                          <CFSET ArrayAppend(test, "#Form["deptvendor_" & machinecount]#")>
                          <CFSET ArrayAppend(test, "#Form["hardwarefailure_" & machineCount]#")>
                          <CFSET ArrayAppend(test, "#Form["thedescription_" & machineCount]#")>
                          <cfset myList = ArrayToList(test, ",")>
                          <cfset anothert = ListFind(form.serialnum)>
                        <cfset test = ArrayNew(1)>
                          <CFSET ArrayAppend(test, "#Form["serialnum_" & machineCount]#")> 
                        <cfset myList = ArrayToList(test, ",")>
                          <cfset anothert = ListFind(form.serialnum)>
                        Thank you,
                        Rach

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          No, keep it as you had in, for example, post #282. These four array creation/setting lines only add the serial number. The array create line should be outside the loop. Only the array append line should be in the loop.

                          Comment

                          • bonneylake
                            Contributor
                            • Aug 2008
                            • 769

                            Originally posted by acoder
                            No, keep it as you had in, for example, post #282. These four array creation/setting lines only add the serial number. The array create line should be outside the loop. Only the array append line should be in the loop.
                            Hey Acoder,

                            Ok i am still a bit confused but are you talking about something like this?

                            here is what i got in full.
                            Code:
                            <CFIF REQUEST_METHOD EQ "POST">
                             
                             <cfquery name="countserials" datasource="CustomerSupport">
                            SELECT pka_serialNo from dbo.tbl_CS_serial where pkb_fk_ticketNo=<cfqueryparam value="#Form.pk_ticketID#">
                             </cfquery>
                             <cfset currSerialNo = 1>
                             <CFLOOP list="#form.serialcount#" index="machineCount">
                              <CFSET serialnum       = Form["serialnum_" & machineCount]>
                             <cfquery name="deleteserialparts" datasource="CustomerSupport">
                             exec usp_CS_Deleteserialparts   
                             <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                             '#Form.pk_ticketID#'
                             </cfquery>
                            <CFSET serialnum       = Form["serialnum_" & machineCount]>
                            <CFSET modelno         = Form["modelno_" & machineCount]>
                            <CFSET producttype     = Form["producttype_" & machineCount]>
                            <CFSET softhardware    = Form["softhardware_" & machineCount]>
                            <CFSET resolution      = Form["resolution_" & machineCount]>
                            <CFSET resdate         = Form["resdate_" & machineCount]>
                            <CFSET resvertified    = Form["resvertified_" & machineCount]>
                            <CFSET vertifidate     = Form["vertifidate_" & machineCount]>
                            <CFSET deptvendor      = Form["deptvendor_" & machinecount]>
                            <CFSET hardwarefailure = Form["hardwarefailure_" & machineCount]>
                            <CFSET thedescription  = Form["thedescription_" & machineCount]>
                            <cfset test = ArrayNew(1)>
                              <CFSET ArrayAppend(test, "#Form["serialnum_" & machineCount]#")> 
                            
                            
                             
                            
                             <!--- inserts information into the serial table--->
                             <cfquery name="serialinsertupdate" datasource="CustomerSupport">
                                exec usp_CS_Updateinsertserial 
                                 <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                                 "#Form.pk_ticketID#",
                                 <cfqueryparam value="#modelno#" CFSQLType = "CF_SQL_VARCHAR">,
                                  <cfqueryparam value="#producttype#" CFSQLType = "CF_SQL_VARCHAR">,
                                 <cfqueryparam value="#softhardware#" CFSQLType = "CF_SQL_VARCHAR">,
                                 <cfqueryparam value="#resolution#" CFSQLType = "CF_SQL_VARCHAR">,
                                 <cfqueryparam value="#resdate#">,
                                 <cfqueryparam value="#resvertified#" CFSQLType = "CF_SQL_VARCHAR">,
                                 <cfqueryparam value="#vertifidate#">,
                                <cfqueryparam value="#deptvendor#" CFSQLType = "CF_SQL_VARCHAR">,
                                 <cfqueryparam value="#hardwarefailure#" CFSQLType = "CF_SQL_VARCHAR">   
                                 </cfquery>
                            
                             <!---Inserts information into notes_descr table.--->
                             <cfquery name="description" datasource="CustomerSupport">
                                exec usp_CS_Insertdescription
                               <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                               '#Form.pk_ticketID#',
                                <cfqueryparam value="#thedescription#" CFSQLType = "CF_SQL_VARCHAR">,
                               '#Form.fk_addedBy#'
                             </cfquery>
                              
                              <!---Inserts parts information into parts table.--->
                              <!---because it is a bit we don't use 'ticks' around defective for parts table--->
                             <cfparam name="form.partscount#machinecount#" default="">
                             <cfloop list="#form['partscount' & machinecount]#" index="ps">
                            <cfparam name="Form.defective_#ps#_#machinecount#" default="0">
                              <cfparam name="Form.partsreturn_#ps#_#machinecount#" default="0">
                             <CFSET hcpn            = Form["hcpn_" & "#ps#" & "_#machinecount#"]>
                             <CFSET partsreturn     = Form["partsreturn_" & "#ps#" & "_#machinecount#"]>
                             <CFSET defective       = Form["defective_" & "#ps#" & "_#machinecount#"]>
                             <CFSET rma             = Form["rma_" & "#ps#" & "_#machineCount#"]>
                            <cfquery name="parts" datasource="CustomerSupport">
                               exec usp_CS_Updateinsertparts 
                              <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                               '#Form.pk_ticketID#',
                                <cfqueryparam value="#hcpn#" CFSQLType = "CF_SQL_VARCHAR">,
                                <cfqueryparam value="#partsreturn#" CFSQLType = "CF_SQL_VARCHAR">,
                                <cfqueryparam value="#rma#" CFSQLType = "CF_SQL_VARCHAR">,
                               <cfqueryparam value="#defective#" CFSQLType = "CF_SQL_BIT">
                             </cfquery> 
                            </cfloop>
                            
                            </CFLOOP>
                            <cfset myList = ArrayToList(test, ",")>
                            <cfset anothert = ListFind(form.serialnum)>
                            <cfloop query="countserials">
                            
                            <CFSET serialnum = #pka_serialNo#>
                            <cfquery name="deleteserialparts" datasource="CustomerSupport">
                            exec usp_CS_Deleteserialparts   
                            <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                            '#Form.pk_ticketID#'
                            </cfquery>
                            </cfloop>
                            
                             </CFIF>

                            Thank you,
                            Rach

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              Remove the deleteserialpar ts query from the first loop. You can also remove line 8 because it's a repeat of line 14.

                              Line 25 should be above the loop because you don't want to create a new array for each serial.

                              Finally, line 79 should be inside the countserials loop for comparison though it'll need to be in a cfif tag to actually compare or you could use the variable for comparison.

                              Comment

                              • bonneylake
                                Contributor
                                • Aug 2008
                                • 769

                                Originally posted by acoder
                                Remove the deleteserialpar ts query from the first loop. You can also remove line 8 because it's a repeat of line 14.

                                Line 25 should be above the loop because you don't want to create a new array for each serial.

                                Finally, line 79 should be inside the countserials loop for comparison though it'll need to be in a cfif tag to actually compare or you could use the variable for comparison.
                                Hey Acoder,

                                Only part i am confused about is the cfif part, how would i make this into a cfif?

                                Code:
                                <cfset anothert = ListFind(form.serialnum)>
                                But here is what i have in full besides that

                                Code:
                                <CFIF REQUEST_METHOD EQ "POST">
                                 
                                 <cfquery name="countserials" datasource="CustomerSupport">
                                SELECT pka_serialNo from dbo.tbl_CS_serial where pkb_fk_ticketNo=<cfqueryparam value="#Form.pk_ticketID#">
                                 </cfquery>
                                 <cfset currSerialNo = 1>
                                 <cfset test = ArrayNew(1)>
                                 <CFLOOP list="#form.serialcount#" index="machineCount">
                                <CFSET serialnum       = Form["serialnum_" & machineCount]>
                                <CFSET modelno         = Form["modelno_" & machineCount]>
                                <CFSET producttype     = Form["producttype_" & machineCount]>
                                <CFSET softhardware    = Form["softhardware_" & machineCount]>
                                <CFSET resolution      = Form["resolution_" & machineCount]>
                                <CFSET resdate         = Form["resdate_" & machineCount]>
                                <CFSET resvertified    = Form["resvertified_" & machineCount]>
                                <CFSET vertifidate     = Form["vertifidate_" & machineCount]>
                                <CFSET deptvendor      = Form["deptvendor_" & machinecount]>
                                <CFSET hardwarefailure = Form["hardwarefailure_" & machineCount]>
                                <CFSET thedescription  = Form["thedescription_" & machineCount]>
                                <CFSET ArrayAppend(test, "#Form["serialnum_" & machineCount]#")> 
                                
                                
                                 <!--- inserts information into the serial table--->
                                 <cfquery name="serialinsertupdate" datasource="CustomerSupport">
                                    exec usp_CS_Updateinsertserial 
                                     <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                                     "#Form.pk_ticketID#",
                                     <cfqueryparam value="#modelno#" CFSQLType = "CF_SQL_VARCHAR">,
                                      <cfqueryparam value="#producttype#" CFSQLType = "CF_SQL_VARCHAR">,
                                     <cfqueryparam value="#softhardware#" CFSQLType = "CF_SQL_VARCHAR">,
                                     <cfqueryparam value="#resolution#" CFSQLType = "CF_SQL_VARCHAR">,
                                     <cfqueryparam value="#resdate#">,
                                     <cfqueryparam value="#resvertified#" CFSQLType = "CF_SQL_VARCHAR">,
                                     <cfqueryparam value="#vertifidate#">,
                                    <cfqueryparam value="#deptvendor#" CFSQLType = "CF_SQL_VARCHAR">,
                                     <cfqueryparam value="#hardwarefailure#" CFSQLType = "CF_SQL_VARCHAR">   
                                     </cfquery>
                                
                                 <!---Inserts information into notes_descr table.--->
                                 <cfquery name="description" datasource="CustomerSupport">
                                    exec usp_CS_Insertdescription
                                   <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                                   '#Form.pk_ticketID#',
                                    <cfqueryparam value="#thedescription#" CFSQLType = "CF_SQL_VARCHAR">,
                                   '#Form.fk_addedBy#'
                                 </cfquery>
                                  
                                  <!---Inserts parts information into parts table.--->
                                  <!---because it is a bit we don't use 'ticks' around defective for parts table--->
                                 <cfparam name="form.partscount#machinecount#" default="">
                                 <cfloop list="#form['partscount' & machinecount]#" index="ps">
                                <cfparam name="Form.defective_#ps#_#machinecount#" default="0">
                                  <cfparam name="Form.partsreturn_#ps#_#machinecount#" default="0">
                                 <CFSET hcpn            = Form["hcpn_" & "#ps#" & "_#machinecount#"]>
                                 <CFSET partsreturn     = Form["partsreturn_" & "#ps#" & "_#machinecount#"]>
                                 <CFSET defective       = Form["defective_" & "#ps#" & "_#machinecount#"]>
                                 <CFSET rma             = Form["rma_" & "#ps#" & "_#machineCount#"]>
                                <cfquery name="parts" datasource="CustomerSupport">
                                   exec usp_CS_Updateinsertparts 
                                  <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                                   '#Form.pk_ticketID#',
                                    <cfqueryparam value="#hcpn#" CFSQLType = "CF_SQL_VARCHAR">,
                                    <cfqueryparam value="#partsreturn#" CFSQLType = "CF_SQL_VARCHAR">,
                                    <cfqueryparam value="#rma#" CFSQLType = "CF_SQL_VARCHAR">,
                                   <cfqueryparam value="#defective#" CFSQLType = "CF_SQL_BIT">
                                 </cfquery> 
                                </cfloop>
                                <cfset anothert = ListFind(form.serialnum)>
                                </CFLOOP>
                                
                                
                                <cfset myList = ArrayToList(test, ",")>
                                <cfloop query="countserials">
                                <CFSET serialnum = #pka_serialNo#>
                                <cfquery name="deleteserialparts" datasource="CustomerSupport">
                                exec usp_CS_Deleteserialparts   
                                <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                                '#Form.pk_ticketID#'
                                </cfquery>
                                </cfloop>
                                
                                 </CFIF>
                                Thank you,
                                Rach

                                Comment

                                Working...