Solved

ColdFusion Help with update statement

Posted on 2014-03-01
2
234 Views
Last Modified: 2014-03-01
I have a working update statement that updates more than one record at a time (with one table) and need to alter to accommodate another table of alterations, meaning some records of the main table have a alteration record attached and some don't.

I'm using counter for multiple inputs:
<cfloop from="1" to="#form.numOfFields#" index="counter">
       <!--- extract values of form fields --->
       <cfset variables.keyID   = FORM["keyid_"& counter]>
       <cfset variables.date = FORM["date_"& counter]>
Problem:
When I added this statement, to receive inputs for the alteration table, I receive errors due to not all records from the main table, have records from the alteration table:
      <cfset variables.AlterationTabledate = FORM["REC_DATE_B"& counter]>
This statement works when all records being displayed have an alteration record.

Error received if all records displayed do not have an alteration record:
Element DATE_B2 is undefined in a Java object of type class coldfusion.filter.FormScope.

How can I make this update statement work when not all records of the main table have an alternate record attached?
0
Comment
Question by:DJPr0
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39897658
(BTW, Since your question is about CF, it really should have been posted under one of the CF topics, not Access (it won't get the right attention there).  I just saw it by accident... )

If I'm understanding correctly, either

a) Use cfparam to assign a default value for the field, so it always exists. That'll avoid the error
 
<cfparam name="FORM.REC_DATE_B#counter#" default="(some default value")>
<cfset variables.AlterationTabledate = FORM["REC_DATE_B"& counter]>

b) OR you could use structKeyExists and only do something if that field DOES exist

<cfif structKeyExists(FORM, "REC_DATE_B"& counter)>
       the form field exists, do something here
</cfif>

Which one is better all depends what your code is doing.
0
 

Author Closing Comment

by:DJPr0
ID: 39897910
Plan b worked perfectly - thanks!
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question