armanbena
asked on
condition failing within cfif statement
Hi,
I have a cfloop statement, within that there is an if statement, I am moving 2 files if statusflag is approved (1), to determine the type of file being moved, I am looking at a field to see if it holds a value. The problem is the condition fails where I'm testing that field ListResult.NPSGroupNumber. I tried going about it a few different ways, switching order, creating another cfif, instead of cfelseif but no luck. Any suggestions?
<CFLOOP from = "1" to = "#RecordCount#" index = "i">
<cfif isdefined('FORM.GP#i#')>
<cfset gpValue = FORM["gp"& i]>
<CFQUERY DATASOURCE="Obi-default" NAME="ListResult" >
select *
from NF_WMI
where TrackingNumber = #i#
</CFQUERY>
<cfif #val(gpValue)# eq 1 and len(ListResult.NPSGroupNum ber) eq 0>
<cffile action="move"
source="#ListResult.BnftCh art_Path#"
destination="\\pwn401av213 \obi-dev\W MI\OBI\App roved\#Lis tResult.LO B#\#ListRe sult.Group No#bnftcha rt.obi">
<!--- <cffile action="move"
source="#ListResult.CertRi der_Path#"
destination="\\pwn401av213 \obi-dev\W MI\HTML\Ap proved\#Li stResult.L OB#\#ListR esult.Grou pNo#bnftce rt.html">
</cfif>
--->
<cfelseif #val(gpValue)# eq 1 and isdefined(ListResult.NPSGr oupNumber) >
<cfset FileWrite("\\pwn401av213\o bi-dev\WMI \OBI\Appro ved\testin g.txt\","H ello World")>
<cfelseif #val(gpValue)# eq 0>
<cfinclude template="rejected_email.c fm">
</cfif>
<CFQUERY name="apprvd" DATASOURCE="Obi-default" result="test">
UPDATE NF_WMI
SET StatusFlag = #val(gpValue)#,
Approved_By = #submittedByQry.employeeNu mber#,
Approved_Date = #Now()#
WHERE TrackingNumber = #i#
</CFQUERY>
</cfif>
</CFLOOP>
I have a cfloop statement, within that there is an if statement, I am moving 2 files if statusflag is approved (1), to determine the type of file being moved, I am looking at a field to see if it holds a value. The problem is the condition fails where I'm testing that field ListResult.NPSGroupNumber.
<CFLOOP from = "1" to = "#RecordCount#" index = "i">
<cfif isdefined('FORM.GP#i#')>
<cfset gpValue = FORM["gp"& i]>
<CFQUERY DATASOURCE="Obi-default" NAME="ListResult" >
select *
from NF_WMI
where TrackingNumber = #i#
</CFQUERY>
<cfif #val(gpValue)# eq 1 and len(ListResult.NPSGroupNum
<cffile action="move"
source="#ListResult.BnftCh
destination="\\pwn401av213
<!--- <cffile action="move"
source="#ListResult.CertRi
destination="\\pwn401av213
</cfif>
--->
<cfelseif #val(gpValue)# eq 1 and isdefined(ListResult.NPSGr
<cfset FileWrite("\\pwn401av213\o
<cfelseif #val(gpValue)# eq 0>
<cfinclude template="rejected_email.c
</cfif>
<CFQUERY name="apprvd" DATASOURCE="Obi-default" result="test">
UPDATE NF_WMI
SET StatusFlag = #val(gpValue)#,
Approved_By = #submittedByQry.employeeNu
Approved_Date = #Now()#
WHERE TrackingNumber = #i#
</CFQUERY>
</cfif>
</CFLOOP>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thank you Sir....
wait, the isDefined() statement is not correct...
When testing a variable to see if it exists, you need to use quotes...
Typically like this.... isDefined("form.firstName" )
without the quotes, you are testing the VALUE of the variable to see if THAT exists as a variable...
so, in this case...
isdefined(ListResult.NPSGr oupNumber)
Let's say ListResult.NPSGroupNumber is 123. That means isDefined is testing to see if variables.123 exists as a variable... which I assume it does not.
You would want to use isdefined("ListResult.NPSG roupNumber ")
but as I said above, since you are testing a query, the value will always exist as long as that column exists in the cfquery
In short, remove the isDefined() from the code
When testing a variable to see if it exists, you need to use quotes...
Typically like this.... isDefined("form.firstName"
without the quotes, you are testing the VALUE of the variable to see if THAT exists as a variable...
so, in this case...
isdefined(ListResult.NPSGr
Let's say ListResult.NPSGroupNumber is 123. That means isDefined is testing to see if variables.123 exists as a variable... which I assume it does not.
You would want to use isdefined("ListResult.NPSG
but as I said above, since you are testing a query, the value will always exist as long as that column exists in the cfquery
In short, remove the isDefined() from the code
ASKER
Okay, I removed the isDefined tag but it still fails. Not sure what is wrong. This is what I have now:
<CFLOOP from = "1" to = "#RecordCount#" index = "i">
<cfif isdefined('FORM.GP#i#')>
<cfset gpValue = FORM["gp"& i]>
<CFQUERY DATASOURCE="Obi-default" NAME="ListResult" >
select *
from NF_WMI
where TrackingNumber = #i#
</CFQUERY>
<cfif #val(gpValue)# eq 0 >
<cfinclude template="rejected_email.c fm">
<cfelseif #val(gpValue)# eq 1 and len(ListResult.NPSGroupNum ber) eq 0>
<cffile action="move"
source="#ListResult.BnftCh art_Path#"
destination="\\pwn401av213 \obi-dev\W MI\OBI\App roved\#Lis tResult.LO B#\#ListRe sult.Group No#bnftcha rt.obi">
<!--- <cffile action="move"
source="#ListResult.CertRi der_Path#"
destination="\\pwn401av213 \obi-dev\W MI\HTML\Ap proved\#Li stResult.L OB#\#ListR esult.Grou pNo#bnftce rt.html">
</cfif>
--->
<cfelseif #val(gpValue)# eq 1>
<cfset FileWrite("\\pwn401av213\o bi-dev\WMI \OBI\Appro ved\testin g.txt\","H ello World")>
</cfif >
<CFQUERY name="apprvd" DATASOURCE="Obi-default" result="test">
UPDATE NF_WMI
SET StatusFlag = #val(gpValue)#,
Approved_By = #submittedByQry.employeeNu mber#,
Approved_Date = #Now()#
WHERE TrackingNumber = #i#
</CFQUERY>
</cfif>
</CFLOOP>
<CFLOOP from = "1" to = "#RecordCount#" index = "i">
<cfif isdefined('FORM.GP#i#')>
<cfset gpValue = FORM["gp"& i]>
<CFQUERY DATASOURCE="Obi-default" NAME="ListResult" >
select *
from NF_WMI
where TrackingNumber = #i#
</CFQUERY>
<cfif #val(gpValue)# eq 0 >
<cfinclude template="rejected_email.c
<cfelseif #val(gpValue)# eq 1 and len(ListResult.NPSGroupNum
<cffile action="move"
source="#ListResult.BnftCh
destination="\\pwn401av213
<!--- <cffile action="move"
source="#ListResult.CertRi
destination="\\pwn401av213
</cfif>
--->
<cfelseif #val(gpValue)# eq 1>
<cfset FileWrite("\\pwn401av213\o
</cfif >
<CFQUERY name="apprvd" DATASOURCE="Obi-default" result="test">
UPDATE NF_WMI
SET StatusFlag = #val(gpValue)#,
Approved_By = #submittedByQry.employeeNu
Approved_Date = #Now()#
WHERE TrackingNumber = #i#
</CFQUERY>
</cfif>
</CFLOOP>
> Okay, I removed the isDefined tag but it still fails. Not sure what is wrong. This is what I have now:
what does "fails" mean exactly?
What happened with the flags (the <h1> statements) ... which ones displayed and which ones didn't. Which area did you expect to enter and did not, which flag is showing when you had that situation?
what does "fails" mean exactly?
What happened with the flags (the <h1> statements) ... which ones displayed and which ones didn't. Which area did you expect to enter and did not, which flag is showing when you had that situation?
There is the strong possibility that the condition will never be met.
You have no final cfelse statement.
So if #val(gpValue)# eq 1 and len(ListResult.NPSGroupNum ber) eq 0 does not evaluate to true, then no path will be taken.
There are 4 possibilities for the outer cfif
val(gpval) 1 len(ListResult.NPSGroupNum ber) 1
val(gpval) 0 len(ListResult.NPSGroupNum ber)1
val(gpval) 1 len(ListResult.NPSGroupNum ber) 0
val(gpval)0 len(ListResult.NPSGroupNum ber) 0
You have no final cfelse statement.
So if #val(gpValue)# eq 1 and len(ListResult.NPSGroupNum
There are 4 possibilities for the outer cfif
val(gpval) 1 len(ListResult.NPSGroupNum
val(gpval) 0 len(ListResult.NPSGroupNum
val(gpval) 1 len(ListResult.NPSGroupNum
val(gpval)0 len(ListResult.NPSGroupNum
> So if #val(gpValue)# eq 1 and len(ListResult.NPSGroupNum ber) eq 0 does not evaluate to true, then no path will be taken.
well, not quite, if gpvalue and 1, then it will go to the last CFELSEIF statement regardless of the value of len(NPSgroupNumber)
The cases are these...
val(gpval) 0 and len(ListResult.NPSGroupNum ber) is any value
val(gpval) 1 and len(ListResult.NPSGroupNum ber) is 0
val(gpval) 1 and len(ListResult.NPSGroupNum ber) is any value
what if gpval is not 0 or 1 ... then nothing happens...
So, the changes are your gpval is some number other than 1 or 0
That's why I proposed the CFIF structure above... you don't have to re-test conditions and some condition is always met. Add the <h1> tags to display and let you know where you are in the code...
well, not quite, if gpvalue and 1, then it will go to the last CFELSEIF statement regardless of the value of len(NPSgroupNumber)
The cases are these...
val(gpval) 0 and len(ListResult.NPSGroupNum
val(gpval) 1 and len(ListResult.NPSGroupNum
val(gpval) 1 and len(ListResult.NPSGroupNum
what if gpval is not 0 or 1 ... then nothing happens...
So, the changes are your gpval is some number other than 1 or 0
That's why I proposed the CFIF structure above... you don't have to re-test conditions and some condition is always met. Add the <h1> tags to display and let you know where you are in the code...
I have doubt in this line
<cfset gpValue = FORM["gp"& i]>
try with
<cfset gpValue = evaluate("gp" & i)>