Solved

Coldfusion: Issue with variable not being created/set

Posted on 2014-11-04
11
195 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
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 19

Assisted Solution

by:erikTsomik
erikTsomik earned 166 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 167 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 167 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now