Solved

Coldfusion: Issue with variable not being created/set

Posted on 2014-11-04
11
202 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
push Book Today button to right 10 37
hosting images 4 35
xss alert in domino url 9 33
Lucee & <cftransaction.... />  WITAF? 10 16
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

829 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