Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

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

0
J C
Asked:
J C
  • 5
  • 2
  • 2
  • +1
3 Solutions
 
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now