Coldfusion: Issue with variable not being created/set

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

J CAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

erikTsomikSystem Architect, CF programmer Commented:
just dump the query and see what the value is

<cfdump var="#searchResults#">
0
_agx_Commented:
>> #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
gdemariaCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

J CAuthor Commented:
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
J CAuthor Commented:
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
erikTsomikSystem Architect, CF programmer Commented:
well it depends which table are you using paymentinfobylot_view or paymentinfobycheck_view
0
_agx_Commented:
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
gdemariaCommented:
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
J CAuthor Commented:
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
J CAuthor Commented:
Thank you!
0
J CAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.