Coldfusion error: element is undefined - help needed

roger v
roger v used Ask the Experts™
on
Hi,

I have a coldfusion form that loops through a bunch of form fields using the #currentrow#. But I keep getting an error when I'm trying to do an update query. This is the error I get:

Element txt_approvers_1 is undefined in a Java object of type class coldfusion.filter.FormScope.

I have a checkbox that when checked, disables the txt_approvers_#currentrow# textbox and I'm not sure if that is causing this error. Code is attached. Could someone point me in the right direction?
<!---Initialize error string--->
     <cfset strError = "">
	 <!---begin form submit operations--->
     <cfif StructKeyExists(form,'submitvalue') and form.submitvalue eq 1>
		<!---<cfdump var="#form#"><cfabort>--->
		<cfset stInactiveUsers = structNew()>
    		<cfset stActiveUsers   = structNew()>
            	<cfset stDeDupe = structNew()>
                
				<cfloop index="key" list="#structKeyList(form)#">
       				<cfset userId = form[key]>
                    
       					<cfif key contains "txt_"  and len(trim(userID))>
                        	<cfset arrUserIds = ArrayNew(1)>
                            <cfset arrUserIds = ListToArray(userId, ",")>
                            
                            <cfloop from="1" to="#ArrayLen(arrUserIds)#" index="arridx">
								
          						<cfquery name="checkforuser" datasource="#application.datasource#">
            						select userid from hr_table
              						where userid = '#arrUserIds[arridx]#'
             						and emp_status_code = 'A'
          						</cfquery>
          					<cfif checkforuser.recordcount neq 0>
                                <cfset stActiveUsers[arrUserIds[arridx]] = checkforuser.userid>
          			 		<cfelse>
               					<!---Inactive /Not Found<br>--->
              					<cfset stInactiveUsers[arrUserIds[arridx]] = "Inactive">
           					</cfif>
                            </cfloop>
       					</cfif>
    			</cfloop>
                
		<!---if there are inactive users--->
		<cfif Not StructIsEmpty(stInactiveUsers)>
			<cfset strError = "Error!">
        	<cfsavecontent variable="displayError">
        		
    			<div style="width:500px; height:120px"><p style="color:#F00; font-weight:bold">The following users are not active employees. All ADMINS have to be active employees. Not saved!</p> 
    			<cfloop collection="#stInactiveUsers#" item="idx1">
					<cfquery name="qryGetNames" datasource="#application.datasource#">
						select userid, lastName, firstName
						FROM	hr_table
						WHERE	userid = '#idx1#'
					</cfquery>
					<cfif qryGetNames.recordcount neq 0>
						<cfoutput query="qryGetNames">
							<span style="color:##333; font-weight:bold">userid: </span><a href="http://xxx.xxxx.xxx/cgi-bin/xxx.pl?id=#idx1#" title="Go to User screen" target="_blank"> <span style="color:##F00; font-weight:bold"> #userid#</span>&nbsp;&nbsp;#lastname#, #firstname# </a><!---<cfdump var="#stInactiveUsers#">---><br/><br />
						</cfoutput>
					<cfelse>
						<cfoutput> #idx1#<br /></cfoutput>
					</cfif>
                 </cfloop>
    			</div>
            </cfsavecontent>
        <cfelse><!---insert records--->
			<!---first delete existing records--->
			<cfquery name="qryDeleteUsers" datasource="#application.datasource#">
				delete from dbo.tb_Process_Role_Contact
				where process_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#val(url.processid)#">
			</cfquery>
			<!---end delete--->
        	<!---<cfdump var="#form#"><cfabort>--->
        	<cfloop index="loopCount" from="1" to="#val(form.hrecordcount)#">
            		<cfset variables.jobname = form["jobname_#LoopCount#"]>
                	<cfset variables.admins = form["txt_admins_#LoopCount#"]>
					<cfset variables.approvers = form["txt_approvers_#LoopCount#"]>
					<cfset variables.esc_approvers = form["txt_escalation_approvers_#LoopCount#"]>
                    <cfset variables.second_approvers = form["txt_secondlevel_approvers_#loopcount#"]>
                    <cfset variables.second_esc_approvers = form["txt_secondlevel_escalation_approvers_#loopcount#"]>
					<cfset lstExistingUsers = "">
					
                    <cfloop from="1" to="5" index="idx2">
                    	<cfswitch expression="#idx2#">
              				<cfcase value="1">       
                            	<cfset role = variables.admins>
                                <cfset rname = variables.jobname>
								
            				</cfcase>
            				<cfcase value="2">
                        		<cfset role =  variables.approvers>
                                <cfset rname = variables.jobname>
								
            				</cfcase>
            				<cfcase value="3">
                        		<cfset role = variables.esc_approvers>
                                <cfset rname = variables.jobname>
								
            				</cfcase>
            				<cfcase value="4">
                        		<cfset role = variables.second_approvers>
                                <cfset rname = variables.jobname>
								
            				</cfcase>
            				<cfcase value="5">
                        		<cfset role = variables.second_esc_approvers>
                                <cfset rname = variables.jobname>
								
            				</cfcase>
        				</cfswitch>
					<!---check for multpile userid's--->
					<cfset debugNum = 0>
                    <cfif listlen(PreserveSingleQuotes(role),',') gte 2>
                    	<cfloop index="r_role" list="#PreserveSingleQuotes(role)#" delimiters=",">
							<cftry>
									<cfquery name="qryAddAdmins" datasource="#application.datasource#">
										insert into dbo.tb_Process_Role_Contact 
                							(process_id,Version,jobname,
											Process_contact_role_id,Process_contact_userid,Process_contact_Actv_ind,
											Process_contact_DTm_Upt)
										values	(<cfqueryparam cfsqltype="cf_sql_integer" value="#val(url.processid)#">,'1.0','#preservesinglequotes(rname)#',#idx2#,<cfqueryparam cfsqltype="cf_sql_varchar" value="#r_role#">,'Yes',getDate())
									</cfquery>
									<cfset lstExistingUsers = ListAppend(lstExistingUsers,r_role)>
									<cfset actionPerformed = "userid's added.">
                        <cfcatch type="any">
                        	<cfset isDuplicate = "true">
                        	<p style="color:##F00; font-weight:bold; font-size:12px">Error: <cfoutput>#cfcatch.Message#</cfoutput></p>
                        </cfcatch>
                        </cftry>
                    </cfloop>
                   <!---<cfelse>--->
					<cfelseif listlen(PreserveSingleQuotes(role),',') gte 1>
                   		<cftry>
         					<cfquery name="qryAddAdmins2" datasource="#application.datasource#">
             					insert into dbo.tb_Process_Role_Contact 
                						(process_id,Version,jobname,
										Process_contact_role_id,Process_contact_userid,Process_contact_Actv_ind,
										Process_contact_DTm_Upt)
                				values	(<cfqueryparam cfsqltype="cf_sql_integer" value="#val(url.processid)#">,'1.0','#preservesinglequotes(rname)#',#idx2#,<cfqueryparam cfsqltype="cf_sql_varchar" value="#role#">,'Yes',getDate())
            				</cfquery>
							<cfset lstExistingUsers = ListAppend(lstExistingUsers,role)>
							<cfset actionPerformed = "userid's added.">
                         <cfcatch type="any">
                         	<cfset isDuplicate = "true">
                        	<p style="color:##F00; font-weight:bold; font-size:12px">Error: <cfoutput> #cfcatch.Message#</cfoutput></p>
                        </cfcatch>
                        </cftry>
                        
                   </cfif>
             	</cfloop> 
             </cfloop>	
        	
       </cfif>
	</cfif>
	<!---end form submit operations--->

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Brijesh ChauhanStaff IT Engineer

Commented:
txt_approvers_#currentrow# -- You have to say .. #query_name.currentRow#.. where query_name is the name of the query ...
I agree with Brij that it would be nice if you scoped your currentRow variable, but that's not the problem in this block of code, it's not even used here.  But you should always scope your variables :)

If you disable a form tag, that tag does not pass a value when the form is submitted.  That means there will be no form scoped variable for that form field.

To resolve this, you can use cfparam to ensure the variable exists, something like this...

       <cfloop index="loopCount" from="1" to="#val(form.hrecordcount)#">
                      <cfset variables.jobname = form["jobname_#LoopCount#"]>
                    <cfset variables.admins = form["txt_admins_#LoopCount#"]>
                   <cfparam name="form.txt_approvers_#LoopCount#" default="">
                   <cfset variables.approvers = form["txt_approvers_#LoopCount#"]>



just an off-topic tip.  It seems that the two parts of this CFIF statement are identical in what they do..

 
<cfset debugNum = 0>
<cfif listlen(PreserveSingleQuotes(role),',') gte 2>
  <cfloop index="r_role" list="#PreserveSingleQuotes(role)#" delimiters=",">
  <cftry>
	<cfquery name="qryAddAdmins" datasource="#application.datasource#">
		insert into dbo.tb_Process_Role_Contact 
        							(process_id,Version,jobname,
			Process_contact_role_id,Process_contact_userid,Process_contact_Actv_ind,
			Process_contact_DTm_Upt)
		values	(<cfqueryparam cfsqltype="cf_sql_integer" value="#val(url.processid)#">,'1.0','#preservesinglequotes(rname)#',#idx2#,<cfqueryparam cfsqltype="cf_sql_varchar" value="#r_role#">,'Yes',getDate())
	</cfquery>
	<cfset lstExistingUsers = ListAppend(lstExistingUsers,r_role)>
	<cfset actionPerformed = "userid's added.">
    <cfcatch type="any">
    	<cfset isDuplicate = "true">
    	<p style="color:##F00; font-weight:bold; font-size:12px">Error: <cfoutput>#cfcatch.Message#</cfoutput></p>
    </cfcatch>
    </cftry>
   </cfloop>
<cfelseif listlen(PreserveSingleQuotes(role),',') gte 1>
    <cftry>
    <cfquery name="qryAddAdmins2" datasource="#application.datasource#">
      insert into dbo.tb_Process_Role_Contact 
      (process_id,Version,jobname,
      Process_contact_role_id,Process_contact_userid,Process_contact_Actv_ind,
      Process_contact_DTm_Upt)
      values	(<cfqueryparam cfsqltype="cf_sql_integer" value="#val(url.processid)#">,'1.0','#preservesinglequotes(rname)#',#idx2#,<cfqueryparam cfsqltype="cf_sql_varchar" value="#role#">,'Yes',getDate())
    </cfquery>
    <cfset lstExistingUsers = ListAppend(lstExistingUsers,role)>
    <cfset actionPerformed = "userid's added.">
     <cfcatch type="any">
     	<cfset isDuplicate = "true">
    	<p style="color:##F00; font-weight:bold; font-size:12px">Error: <cfoutput> #cfcatch.Message#</cfoutput></p>
    </cfcatch>
    </cftry>
            
       </cfif>
 	</cfloop> 
 </cfloop>	

</cfif>

Open in new window


The CFLOOP function can work with a list of just one item, so you really don't need to test the listLen() at all.   That is, the CFLOOP will work with a list of "1,2,3,4" or a list that has one element "3"

So the code could just be...

 
<cfset debugNum = 0>
  <cfloop index="r_role" list="#role#" delimiters=",">
  <cftry>
	<cfquery name="qryAddAdmins" datasource="#application.datasource#">
		insert into dbo.tb_Process_Role_Contact 
		(process_id,Version,jobname,
			Process_contact_role_id,Process_contact_userid,Process_contact_Actv_ind,
			Process_contact_DTm_Upt)
		values	(<cfqueryparam cfsqltype="cf_sql_integer" value="#val(url.processid)#">,'1.0','#rname#',#idx2#,<cfqueryparam cfsqltype="cf_sql_varchar" value="#r_role#">,'Yes',getDate())
	</cfquery>
	<cfset lstExistingUsers = ListAppend(lstExistingUsers,r_role)>
	<cfset actionPerformed = "userid's added.">
    <cfcatch type="any">
     	<cfset isDuplicate = "true">
    	<p style="color:##F00; font-weight:bold; font-size:12px">Error: <cfoutput>#cfcatch.Message#</cfoutput></p>
    </cfcatch>
    </cftry>
   </cfloop>

Open in new window

Author

Commented:
@gde:

"<cfparam name="form.txt_approvers_#LoopCount#" default=""> "

Huh, I hadn't even thought about that! Yes, you're right, since the text box is disabled if the check box is checked, it is not being passed. Duh,,,that didn't even strike me. :(

Let me try the cfparam and see if that happens. thanks as usual.

roger

Author

Commented:
@gde:

No luck. I still get the following error:

Element txt_approvers_1 is undefined in a Java object of type class coldfusion.filter.FormScope.
what line?  Can you show the block of code around the line shown in the error...

Author

Commented:
Here is the debug output from the error:

The error occurred in C:\inetpub\wwwroot\xxx\JobAdmin.cfm: line 120
 
118 :                                                 <input type="hidden" name="txt_hChkApprovers_#currentrow#" value="#session.manager#">
119 :                                                 <input type="checkbox" name="txt_chk_approvers_#currentrow#" style="size:12px; width:12px; height:12px" value="Y" id="txt_chkApprvrs_#currentrow#" onClick="checkOffApprover(#currentrow#);" />
120 :                                                 <input type="text" name="txt_approvers_#currentrow#" id="txt_approvers_#currentrow#" maxlength="27" style="width:95px; font-size:9px;" value="#REReplace(form['txt_approvers_' & currentrow]," ","","all")#" />
121 :                                           </td>
122 :                             <td>
 
Brijesh ChauhanStaff IT Engineer

Commented:
This is wrong..

REReplace(form['txt_approvers_' & currentrow]," ","","all")

if you want to get it dynamically, you would need to use VARIABLES scope or EVALUATE

REReplace(form[Evaluate('txt_approvers_' & currentrow)]," ","","all")

 Ok, this is a different spot, this time we're in the form.   Same issue, you need to ensure the variable exists.   Where are you populating it?  (ie.  where are you creating it?)

 
  <cfparam name="form.txt_approvers_#currentRow#" default="">

Do you really want to strip out all the spaces within the txt_approvals?  If yes, why don't you do it on the action in stead of when populating the form?   You can write it like this rather than embedding it with the value statement.   Note that REreplace() is over-kill, this is just a simple replace() function...
  <cfset form["txt_approvers_#currentRow#"] = replace(form["txt_approvers_#currentRow#"], " ","", "all")>

This would be the resulting line...

 <input type="text" name="txt_approvers_#currentrow#" id="txt_approvers_#currentrow#" maxlength="27"
         style="width:95px; font-size:9px;" value="#form['txt_approvers_' & currentrow]#" />

This is the correct format....

REReplace(form['txt_approvers_' & currentrow]," ","","all")

or without the reReplace() function it would be...

  form['txt_approvers_' & currentrow]

that is correct.



Sorry, there is no reason to use evaluate or the variables scope here...  
REReplace(form[Evaluate('txt_approvers_' & currentrow)]," ","","all")     --- incorrect

Author

Commented:
" Ok, this is a different spot, this time we're in the form.   Same issue, you need to ensure the variable exists.   Where are you populating it?  (ie.  where are you creating it?)"

GDE, Code attached where I'm populating it. It is essentially the same code that you provided.
<cfif len(strError) eq 0>
		<cfquery name="qryCheckContacts" datasource="#application.datasource#">
			SELECT	process_id
			FROM	tb_process_role_contact
			WHERE	process_id = <cfqueryparam cfsqltype="cf_sql_numeric" value="#val(url.processid)#">
		</cfquery>
		<cfif qryCheckContacts.recordcount gt 0>
			<cfinvoke component="cfc.xxxx.xxx" method="funcGetExistingJobs" returnvariable="qryAllRoles1">
				<cfinvokeargument name="processid" value="#val(url.processid)#">
				<!---<cfinvokeargument name="scopeval2" value="1">--->
			</cfinvoke>
			<cfloop query="qryAllRoles1">
			<cfset form["rolename_"   & qryAllRoles1.currentRow] = qryAllRoles1.rolename>
			<cfset form["txt_admins_"  & qryAllRoles1.currentRow] = qryAllRoles1.admins>
			<cfset form["chk_approvers_"   & qryAllRoles1.currentRow] = "">
			<cfset form["txt_approvers_" & qryAllRoles1.currentRow] = qryAllRoles1.approvers>
			<cfset form["txt_escalation_approvers_" & qryAllRoles1.currentRow] = qryAllRoles1.esc_approvers>
			<cfset form["txt_secondlevel_approvers_" & qryAllRoles1.currentRow] = qryAllRoles1.secondlevel_approvers>
			<cfset form["txt_secondlevel_escalation_approvers_" & qryAllRoles1.currentRow] = qryAllRoles1.secondlevel_esc_approvers>
			</cfloop>
			<cfset form.recordCount = qryAllRoles1.recordCount>
			
		<cfelse>
			<cfinvoke component="cfc.xxx.xxx" method="funcGetJobs" returnvariable="qryAllJobs2">
				<cfinvokeargument name="processid" value="#val(url.processid)#">
				<cfinvokeargument name="scopeval2" value="1">
			</cfinvoke>
			<cfloop query="qryAllRoles2">
				<cfset form["rolename_"   & qryAllRoles2.currentRow] = qryAllRoles2.rolename>
				<cfset form["txt_admins_"  & qryAllRoles2.currentRow] = "">
				<cfset form["chk_approvers_"   & qryAllRoles2.currentRow] = "">
				<cfset form["txt_approvers_" & qryAllRoles2.currentRow] = "">
				<cfset form["txt_escalation_approvers_" & qryAllRoles2.currentRow] = "">
				<cfset form["txt_secondlevel_approvers_" & qryAllRoles2.currentRow] = "">
				<cfset form["txt_secondlevel_escalation_approvers_" & qryAllRoles2.currentRow] = "">
			</cfloop>
			<cfset form.recordCount = qryAllRoles2.recordCount>
		</cfif>
	
     <cfelse>
    	<cfset form.recordCount = form.frmtempItemCounter>
   	</cfif>

Open in new window

Author

Commented:
"Do you really want to strip out all the spaces within the txt_approvals?  If yes, why don't you do it on the action in stead of when populating the form?  "

That is because when I display the existing values, if there are extra spaces, I need to strip them out as I have javascript validation that does not allow for spaces in the textboxes.
Ok, the queries seem to populate the form variable for each record of the query.  That should do it.

However, since the queries / form population is done inside this CFIF statement...

<cfif len(strError) eq 0>
  <cfquery name="qryCheckContacts" datasource="#application.datasource#">
      SELECT      process_id
      FROM      tb_process_role_contact
      WHERE      process_id = <cfqueryparam cfsqltype="cf_sql_numeric" value="#val(url.processid)#">
   </cfquery>
   <cfif qryCheckContacts.recordcount gt 0>


that means when you submit the form, and have an error, it will not repopulate the form variables.   So the variable must exist from the form post.   We know from the action section we did above that if the form field is disabled it will not exist.   So the same principle applies here.  On form post we either go to the action page or, on error, redraw the same form with an error message.  In either case the disabled form field will not exist and we need to use <cfparam> to ensure it exists.

So this block of code should do what you need, if you replace these lines with the error line, it should work (??)  :)


<cfparam name="form.txt_approvers_#currentRow#" default=""> 
<cfset form["txt_approvers_#currentRow#"] = replace(form["txt_approvers_#currentRow#"], " ","", "all")>
<input type="text" name="txt_approvers_#currentrow#" id="txt_approvers_#currentrow#" maxlength="27" 
       style="width:95px; font-size:9px;" value="#form['txt_approvers_' & currentrow]#" />

Open in new window

Author

Commented:
"So this block of code should do what you need, if you replace these lines with the error line, it should work"

I'm confused - does this go inside the actual form? Or on the action page?

This is the form page, true?  I assumed it was...

 
Here is the debug output from the error:

The error occurred in C:\inetpub\wwwroot\xxx\JobAdmin.cfm: line 120
 
118 :                                                 <input type="hidden" name="txt_hChkApprovers_#currentrow#" value="#session.manager#">
119 :                                                 <input type="checkbox" name="txt_chk_approvers_#currentrow#" style="size:12px; width:12px; height:12px" value="Y" id="txt_chkApprvrs_#currentrow#" onClick="checkOffApprover(#currentrow#);" /> 
120 :                                                 <input type="text" name="txt_approvers_#currentrow#" id="txt_approvers_#currentrow#" maxlength="27" style="width:95px; font-size:9px;" value="#REReplace(form['txt_approvers_' & currentrow]," ","","all")#" />
121 :                                           </td>
122 :                             <td>

Open in new window


So, it would end up looking like this...

 
<input type="hidden" name="txt_hChkApprovers_#currentrow#" value="#session.manager#">
 <input type="checkbox" name="txt_chk_approvers_#currentrow#" style="size:12px; width:12px; height:12px" value="Y" id="txt_chkApprvrs_#currentrow#" onClick="checkOffApprover(#currentrow#);" /> 

 <cfparam name="form.txt_approvers_#currentRow#" default=""> 
 <cfset form["txt_approvers_#currentRow#"] = replace(form["txt_approvers_#currentRow#"], " ","", "all")>
 <input type="text" name="txt_approvers_#currentrow#" id="txt_approvers_#currentrow#" maxlength="27" 
        style="width:95px; font-size:9px;" value="#form['txt_approvers_' & currentrow]#" />

Open in new window

Author

Commented:
GDE,

OK I added those lines in the form itself but now I get the following message:

The following users are not active employees:

Y

So it is picking up the value of the checkbox (which is "Y" for yes) and running the query to check if that is an employee or not. If the checkbox is checked, I need to skip that iteration in the cfloop at the begining of the action page. One problem seemingly solved, another created. :(

are you referring to this part of the code on the action page where it checks the hr_table for the user?

I don't see any code that would keep fields out of this area.. only this:

 <cfif key contains "txt_"  and len(trim(userID))>

Any field that has "txt_" in it... ?

Where is the code that tests the checkbox to keep it away from that Query to check the user?

Perhaps you can include your entire CF file (is it one file or two files (form and action page)) ?

<cfloop index="key" list="#structKeyList(form)#">
       				<cfset userId = form[key]>
                    
       					<cfif key contains "txt_"  and len(trim(userID))>
                        	<cfset arrUserIds = ArrayNew(1)>
                            <cfset arrUserIds = ListToArray(userId, ",")>
                            
                            <cfloop from="1" to="#ArrayLen(arrUserIds)#" index="arridx">
								
          						<cfquery name="checkforuser" datasource="#application.datasource#">
            						select userid from hr_table
              						where userid = '#arrUserIds[arridx]#'
             						and emp_status_code = 'A'
          						</cfquery>
          					<cfif checkforuser.recordcount neq 0>
                                <cfset stActiveUsers[arrUserIds[arridx]] = checkforuser.userid>
          			 		<cfelse>
               					<!---Inactive /Not Found<br>--->
              					<cfset stInactiveUsers[arrUserIds[arridx]] = "Inactive">
           					</cfif>
                            </cfloop>
       					</cfif>
    			</cfloop>

Open in new window

sorry, i have to continue in the AM, it's after 1 AM here..

but I don't see how what we just entered (a cfparam to ensure that field values exists) would effect the code like this.   Unless somewhere you are testing for the form field NOT to exist...  otherwise, this has to be a pre-existing condition.

Author

Commented:
@gde:

Ok I got it working. I check for the checkbox, and if it is present I skip it. Then when I insert the values, I insert the value of the checkbox. And when I retrieve the values, if the checkbox value in the table is set to "Yes", I set it to checked. I also modified my javascript validation to accomodate this.

But there is still one bug - after I do the insert, the message still displays a userid that I removed and replaced with another userid. The database insert works fine - the removed userid is replaced with the new userid. But for some reason, the previous userid still keeps displaying as successfully inserted, even though it is not. It looks like the form variable is still holding that value or there is a bug in cfsavecontent. Am I on the right track?
Is this the part of the code you say you're seeing?  
   "The following users are not active employees. All ADMINS have to be active employees. Not saved!"
A say that because it's the only cfsavecontent in the action.. ?

 

But you can't also be updating if that is in the <CFELSE> part of the same CFIF statement.

I would put some flags in to see where the code is going...

By flags I mean...

<h1>AAA</h1>
<h1>BBB</h1>
<h1>CCC</h1>

in various parts of your action to see what parts are being run and not...



Author

Commented:
Gotcha! Let me do that and see if that helps. Will let you know shortly. As per usual, Thanks a million! :)

Author

Commented:
OK, GDE - I think I found where the bug is emanating from, but kinda lost on why it's doing that or how to fix it. Essentially, the cfsavecontent is outside of the cfloops that are inserting data into the table. But based on the struct of active users, it displays the userid and name. I think what is happening is this:

Lets say I first entered userid jharr3433 in the approvers field. And saved it. It saves it just fine. Then, I check the checkbox, at which point the javascript replaces the text in the approvers text box (jharr3433 in this case) with the userid that I get from a hidden field (using document.getelementbyid) of the user's manager which is a session variable. Lets say this userid is btrum8998. Now when I save it, it inserts just fine into the database - it inserts the correct userd - btrum8998 into the table. BUT when I display the cfsavecontent, it still shows the old userid - jharr3433 as well! I've attached the code segment that is doing this - it is at the end inside the cfsavecontent.
<cfelse><!---insert records--->
			<!---first delete existing records--->
			<cfquery name="qryDeleteUsers" datasource="#application.datasource#">
				delete from dbo.tb_Process_Role_Contact
				where Process_Id = <cfqueryparam cfsqltype="cf_sql_integer" value="#val(url.ProcessId)#">
			</cfquery>
			<!---end delete--->
        	<!---<cfdump var="#form#"><cfabort>--->
        	<cfloop index="loopCount" from="1" to="#val(form.hrecordcount)#">
            		<cfset variables.rolename = form["rolename_#LoopCount#"]>
                	<cfset variables.admins = form["txt_admins_#LoopCount#"]>
					 <cfparam name="form.txt_approvers_#LoopCount#" default="">
					<cfparam name="form.txt_chk_approvers_#LoopCount#" default="">
					<cfset variables.chkApprovers = form["txt_chk_approvers_#LoopCount#"]>
					<cfif variables.chkApprovers is "Y">
						<cfset variables.role_contact_source = "User's Manager">
					<cfelse>
						<cfset variables.role_contact_source = "">
					</cfif>
					<cfset variables.approvers = form["txt_approvers_#LoopCount#"]>
					<cfset variables.esc_approvers = form["txt_escalation_approvers_#LoopCount#"]>
                    <cfset variables.second_approvers = form["txt_secondlevel_approvers_#loopcount#"]>
                    <cfset variables.second_esc_approvers = form["txt_secondlevel_escalation_approvers_#loopcount#"]>
					<cfset lstExistingUsers = "">
					
                    <cfloop from="1" to="5" index="idx2">
                    	<cfswitch expression="#idx2#">
              				<cfcase value="1">       
                            	<cfset role = variables.admins>
                                <cfset rname = variables.rolename>
								
            				</cfcase>
            				<cfcase value="2">
                        		<cfset role =  variables.approvers>
                                <cfset rname = variables.rolename>
								
            				</cfcase>
            				<cfcase value="3">
                        		<cfset role = variables.esc_approvers>
                                <cfset rname = variables.rolename>
								
            				</cfcase>
            				<cfcase value="4">
                        		<cfset role = variables.second_approvers>
                                <cfset rname = variables.rolename>
								
            				</cfcase>
            				<cfcase value="5">
                        		<cfset role = variables.second_esc_approvers>
                                <cfset rname = variables.rolename>
								
            				</cfcase>
        				</cfswitch>

                    <cfif listlen(PreserveSingleQuotes(role),',') gte 2>		
                    	<cfloop index="r_role" list="#PreserveSingleQuotes(role)#" delimiters=",">
							<!---<cftry>	--->
									<cfquery name="qryAddAdmins" datasource="#application.datasource#">
										insert into dbo.tb_Process_Role_Contact 
                							(Process_Id,Version,RoleName,
											process_contact_role_id,process_contact_userid,process_contact_Actv_ind,
											process_contact_DTm_Upt,process_contact_upt_userid,RoleNameContactSource)
										values	(<cfqueryparam cfsqltype="cf_sql_integer" value="#val(url.ProcessId)#">,<cfqueryparam cfsqltype="cf_sql_numeric" value="1">,'#preservesinglequotes(rname)#',#idx2#,<cfqueryparam cfsqltype="cf_sql_varchar" value="#r_role#">,'Yes',getDate(),<cfqueryparam cfsqltype="cf_sql_varchar" value="#url.userid#">,<cfqueryparam cfsqltype="cf_sql_varchar" value="#PreserveSingleQuotes(variables.role_contact_source)#">)
									</cfquery>
									<cfset lstExistingUsers = ListAppend(lstExistingUsers,r_role)>
									<cfset actionPerformed = "userid's added.">
                        <!---<cfcatch type="any">
                        	<cfset isDuplicate = "true">
                        	<p style="color:##F00; font-weight:bold; font-size:12px">Error: <cfoutput>#cfcatch.Message#</cfoutput></p>
                        </cfcatch>
                        </cftry>--->
                    </cfloop>

					<cfelseif listlen(PreserveSingleQuotes(role),',') gte 1>
                   		<!---<cftry>--->
         					<cfquery name="qryAddAdmins2" datasource="#application.datasource#">
             					insert into dbo.tb_Process_Role_Contact 
                						(Process_Id,Version,RoleName,
										Engmnt_contact_role_id,Engmnt_contact_userid,Engmnt_contact_Actv_ind,
										Engmnt_contact_DTm_Upt,engmnt_contact_upt_userid,RoleNameContactSource)
                				values	(<cfqueryparam cfsqltype="cf_sql_integer" value="#val(url.ProcessId)#">,<cfqueryparam cfsqltype="cf_sql_integer" value="1">,'#preservesinglequotes(rname)#',#idx2#,<cfqueryparam cfsqltype="cf_sql_varchar" value="#role#">,'Yes',getDate(),<cfqueryparam cfsqltype="cf_sql_varchar" value="#url.userid#">,<cfqueryparam cfsqltype="cf_sql_varchar" value="#PreserveSingleQuotes(variables.role_contact_source)#">)
            				</cfquery>
							<cfset lstExistingUsers = ListAppend(lstExistingUsers,role)>
							<cfset actionPerformed = "userid's added.">
                         <!---<cfcatch type="any">
                         	<cfset isDuplicate = "true">
                        	<p style="color:##F00; font-weight:bold; font-size:12px">Error: <cfoutput> #cfcatch.Message#</cfoutput></p>
                        </cfcatch>
                        </cftry>--->
                        
                   </cfif>
             	</cfloop> 
             </cfloop>	
        	<cfsavecontent variable="displaySuccess">
				<h3>AAA</h3>
              <div style="width:500px; height:120px"><p style="color:#6C3; font-weight:bold">All Users are Active Employees. Successfully Inserted! </p>
                  <cfloop collection="#stActiveUsers#" item="idx2">
					<cfquery name="qryGetNames2" datasource="#application.datasource#">
						select userid, lastName, firstName
						FROM	hr_table
						WHERE	userid = '#idx2#'
					</cfquery>
                      <cfoutput query="qryGetNames2">
                          <span style="color:##333; font-weight:bold">userid:</span> <span style="color:##060; font-weight:bold">#userid#</span><br />
						  <span style="color:##333; font-weight:bold">NAME: &nbsp;&nbsp;&nbsp; </span> <span style="color:##060; font-weight:bold">   #lastname#, #firstname#</span>
						  <br/><br />
                      </cfoutput>
                   </cfloop>
              </div>
            </cfsavecontent>

Open in new window

Author

Commented:
GDE, you're AWESOME! The problem was that I had the hidden field name as "txt_approversmanager_#currentrow#" and in the first loop, since I'm checking for "txt_", it picks up the hidden field as well and hence the bug! Muchas Gracias once again!

Author

Commented:
Oops, there seems to be a new bug! Now I get this error:

Element chk_approvers_1 is undefined in a Java object of type class coldfusion.filter.FormScope.  
 
 
The error occurred in C:\inetpub\wwwroot\xxx\xxx.cfm: line 119
 
117 :                              <td>
118 :                                                 <input type="hidden" name="hChkApprovers_#currentrow#" value="#session.usersmanager#" id="hChkApprovers_#currentrow#">
119 :                                                 <input type="checkbox" name="txt_chk_approvers_#currentrow#" style="size:12px; width:12px; height:12px" value="Y" id="txt_chkApprvrs_#currentrow#" onClick="checkOffApprover(#currentrow#);" <cfif form['chk_approvers_' & currentrow] is "User's Manager">checked="checked"</cfif> />
120 :                                                 <!---<input type="text" name="txt_approvers_#currentrow#" id="txt_approvers_#currentrow#" maxlength="27" style="width:95px; font-size:9px;" value="#REReplace(form['txt_approvers_' & currentrow]," ","","all")#" />--->
121 :                                                 <cfparam name="form.txt_approvers_#currentRow#" default="">
 

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial