?
Solved

Coldfusion: Issue with variable not being created/set

Posted on 2014-11-04
11
Medium Priority
?
206 Views
Last Modified: 2014-11-04
I have inherited a coldfusion site and I am having an issue with where one of the variables that should be created when performing a search does not seem to ever be created.

#searchResults.ruleid# has a blank value. I am not sure where the lookup for the ruleid is happening. I am including the code below where I think it should be happening. Maybe one of you can spot something wrong with it.

<!--- SEARCH VARIABLES --->
<cfif isDefined("FORM.ProjID")>
	<cfset REQUEST.ProjID = FORM.ProjID>
<cfelse>
	<cfset REQUEST.ProjID = 0>
</cfif>
<cfif isDefined("FORM.phase")>
	<cfset REQUEST.phase = FORM.phase>
<cfelse>
	<cfset REQUEST.phase = "">
</cfif>
<cfif isDefined("FORM.srch_checknum")>
	<cfset REQUEST.srch_checknum = FORM.srch_checknum>
<cfelse>
	<cfset REQUEST.srch_checknum = "">
</cfif>
<cfif isDefined("FORM.srch_ruleID")>
	<cfset REQUEST.srch_ruleID = FORM.srch_ruleID>
<cfelse>
	<cfset REQUEST.srch_ruleID = "">
</cfif>
<cfif isDefined("FORM.srch_PONo")>
	<cfset REQUEST.srch_PONo = FORM.srch_PONo>
<cfelse>
	<cfset REQUEST.srch_PONo = "">
</cfif>
<cfif isDefined("FORM.orderBy")>
	<cfset REQUEST.orderBy = FORM.orderBy>
</cfif>

<cfif isDefined("FORM.flag") AND FORM.flag>
	<cfquery name="searchResults" datasource="NewstarSQL">
		SELECT 	*
		<cfif (len(REQUEST.projID) GT 0 AND REQUEST.projID GT 0) OR (len(REQUEST.phase) GT 0 AND REQUEST.phase GT 0)>
			FROM 		paymentinfobylot_view
		<cfelse>
			FROM 		paymentinfobycheck_view
		</cfif>
			WHERE 	1 = 1
						<!--- Project --->
						<cfif (len(REQUEST.projID) GT 0 AND REQUEST.projID GT 0) OR (len(REQUEST.phase) GT 0 AND REQUEST.phase GT 0)>
							<cfif len(REQUEST.projID) GT 0 AND REQUEST.projID GT 0>
								AND projID = '#REQUEST.projID#'
							</cfif>
							<!--- Phase --->
							<cfif len(REQUEST.phase) GT 0 AND REQUEST.phase GT 0>
								AND FirstOfPhase = '#REQUEST.phase#'
							</cfif>
						<cfelseif (isDefined("REQUEST.srch_RuleID") AND len(REQUEST.srch_RuleID) GT 0) OR (isDefined("REQUEST.srch_PONo") AND len(REQUEST.srch_PONo) GT 0)>
							<!--- PO Number --->
							<cfif isDefined("REQUEST.srch_RuleID") AND len(REQUEST.srch_RuleID) GT 0>
								AND RuleID LIKE '%#REQUEST.srch_RuleID#%'
							</cfif>
							<cfif isDefined("REQUEST.srch_PONo") AND len(REQUEST.srch_PONo) GT 0>
								AND PONo LIKE '%#REQUEST.srch_PONo#%'
							</cfif>
						<cfelse>
							AND checknumber LIKE '%#REQUEST.srch_checknum#%'
						</cfif>
						<!--- AID of logged in vendor --->
						AND aid = #REQUEST.aid#
						<!--- UNIQUE KEY --->	<!--- This is the unique key used if more than one builder is using one instance of Newstar --->
						#getReportInfo.reportKey#	
						<!--- CUSTOMIZED QUERY STRING --->
						#getReportInfo.reportQryString#
		ORDER BY checknumber, RuleID, PoNo
	</cfquery>
	<cfset REQUEST.recordCount = searchResults.recordCount>
	<!--- <cfdump var="#searchresults#"><cfabort> --->
</cfif>

Open in new window

0
Comment
Question by:J C
[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
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 19

Assisted Solution

by:erikTsomik
erikTsomik earned 664 total points
ID: 40422210
just dump the query and see what the value is

<cfdump var="#searchResults#">
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 668 total points
ID: 40422248
>> #searchResults.ruleid# has a blank value

Blank is different than not being set.

"ruleID" is a column in one of the tables in your SELECT query.  In CF, if a column value is NULL, it will be treated as a empty string.  Check the db table, that value is probably null.
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 668 total points
ID: 40422250
What do you mean "blank"  value?   Does that mean the value is NULL (empty).   If so, the value is being pulled from the database view,   either
                  FROM             paymentinfobylot_view
or
                  FROM             paymentinfobycheck_view

Did you check to see if the value is populated in these viewsfor  the records being returned?

The ruleID according to the code is fetched from one of these two views.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:J C
ID: 40422258
The query returns a value for ruleid, it is not null. I have some experience coding but not inside of coldfusion.

Did I post the code as far as you can tell where the variable for ruleid should be getting set? My biggest issue at the moment is I cannot tell where the lookup is happening and where the variable is getting created.
0
 

Author Comment

by:J C
ID: 40422272
I ran the cfdump and it is reporting the ruleid as an empty string but if I run the query inside of sql management studio it returns the ruleid when I apply the same filters.
0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 40422281
well it depends which table are you using paymentinfobylot_view or paymentinfobycheck_view
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40422284
If you're getting different results, it's probably not the same SQL. How did you obtain the SQL you used in SSMS?  From the CFDUMP? Can you post that?
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 40422289
It is getting set from your query

SELECT       *
FROM             paymentinfobylot_view
or
SELECT       *
FROM             paymentinfobycheck_view


We know this because the name of the variable you mentioned is searchResults.RUleID and searchResults is the name of this query, so it is referring to this select statement and the column RULEID which is included in the SELECT * (all columns)

As long as the spot where it is blank is referringt o searchResults.RuleID, this should be the source, if it is using a different scope such as FORM.RuleID, or just RULEID, then it could be a different variable and not come from this query
0
 

Author Comment

by:J C
ID: 40422292
I didn't look closely at this. The  paymentinfobycheck_view was returning a ruleid but there was an issue with the  paymentinfobylot_view. I didn't notice that there were two views in the mix here. Thank you guys for your help

	<cfif (len(REQUEST.projID) GT 0 AND REQUEST.projID GT 0) OR (len(REQUEST.phase) GT 0 AND REQUEST.phase GT 0)>
			FROM 		paymentinfobylot_view
		<cfelse>
			FROM 		paymentinfobycheck_view
		</cfif>

Open in new window

0
 

Author Closing Comment

by:J C
ID: 40422297
Thank you!
0
 

Author Comment

by:J C
ID: 40422302
gdemaria,

Thank you for the explanation in your last post. That should have been obvious to me but it wasn't. That will help me going forward. I appreciate it.
0

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

762 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