Solved

condition failing within cfif statement

Posted on 2011-09-26
8
472 Views
Last Modified: 2012-05-12
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.NPSGroupNumber) eq 0>  
           
           
            <cffile action="move"
                    source="#ListResult.BnftChart_Path#"
                    destination="\\pwn401av213\obi-dev\WMI\OBI\Approved\#ListResult.LOB#\#ListResult.GroupNo#bnftchart.obi">
                   
                   
                   <!--- <cffile action="move"
                    source="#ListResult.CertRider_Path#"
                    destination="\\pwn401av213\obi-dev\WMI\HTML\Approved\#ListResult.LOB#\#ListResult.GroupNo#bnftcert.html">
           
            </cfif>      
                        --->
                       
                       
            <cfelseif #val(gpValue)# eq 1 and isdefined(ListResult.NPSGroupNumber) >

                        <cfset FileWrite("\\pwn401av213\obi-dev\WMI\OBI\Approved\testing.txt\","Hello World")>
           
           
            <cfelseif #val(gpValue)# eq 0>
                   
                        <cfinclude template="rejected_email.cfm">
            </cfif>





            <CFQUERY name="apprvd" DATASOURCE="Obi-default" result="test">  
            UPDATE      NF_WMI  
            SET         StatusFlag = #val(gpValue)#,
            Approved_By = #submittedByQry.employeeNumber#,
            Approved_Date =  #Now()#
            WHERE TrackingNumber = #i#
       
                 </CFQUERY>  
     
     

   </cfif>
   
   
   
</CFLOOP>
0
Comment
Question by:armanbena
8 Comments
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 36599211
have you check what gpvalue holding ?

I have doubt in this line

<cfset gpValue = FORM["gp"& i]>

try with

<cfset gpValue = evaluate("gp" & i)>

0
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 36599293

This is the correct format:   <cfset gpValue = FORM["gp"& i]>
anytime you feel like using evaluate() you should turn off your computer until the feeling goes away
:)


I suggest using this nested format with the <h1> flags I put in to see where the code is being entered, that will tell you which variables are not acting as you feel they should...

Note that since the isDefined() is referencing a query, it will always be true..  isdefined(ListResult.NPSGroupNumber)  will always be true
<cfif val(gpValue) eq 1>
               <h1>gpValue is 1</h1>
               <cfif len(ListResult.NPSGroupNumber) eq 0>  
                    <h1>NPSGroupNumber is empty</h1>
                    <cffile action="move"
                            source="#ListResult.BnftChart_Path#"
                            destination="\\pwn401av213\obi-dev\WMI\OBI\Approved\#ListResult.LOB#\#ListResult.GroupNo#bnftchart.obi">
               <cfelse>
                    <h1>NPSGroupNumber has a value</h1>
                    <cfset FileWrite("\\pwn401av213\obi-dev\WMI\OBI\Approved\testing.txt\","Hello World")> 
               </cfif>    
            
           <cfelse> 
               <h1>gpValue is Zero</h1>
               <cfinclude template="rejected_email.cfm">
           </cfif>

Open in new window

0
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 36599327
Thank you Sir....
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 36599400
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.NPSGroupNumber)

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.NPSGroupNumber")

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

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:armanbena
ID: 36710362
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.cfm">
                   
                 
                       
                       
            <cfelseif #val(gpValue)# eq 1 and len(ListResult.NPSGroupNumber) eq 0>  
           
           
           
            <cffile action="move"
                    source="#ListResult.BnftChart_Path#"
                    destination="\\pwn401av213\obi-dev\WMI\OBI\Approved\#ListResult.LOB#\#ListResult.GroupNo#bnftchart.obi">
                   
                   
                   <!--- <cffile action="move"
                    source="#ListResult.CertRider_Path#"
                    destination="\\pwn401av213\obi-dev\WMI\HTML\Approved\#ListResult.LOB#\#ListResult.GroupNo#bnftcert.html">
           
            </cfif>      
                        --->
                       
                       
            <cfelseif #val(gpValue)# eq 1>
                  
                        <cfset FileWrite("\\pwn401av213\obi-dev\WMI\OBI\Approved\testing.txt\","Hello World")>
           
           
            </cfif >





            <CFQUERY name="apprvd" DATASOURCE="Obi-default" result="test">  
            UPDATE      NF_WMI  
            SET         StatusFlag = #val(gpValue)#,
            Approved_By = #submittedByQry.employeeNumber#,
            Approved_Date =  #Now()#
            WHERE TrackingNumber = #i#
       
                 </CFQUERY>  
     
     

   </cfif>
   
   
   
</CFLOOP>
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 36710417
> 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?
0
 

Expert Comment

by:kcjuliff
ID: 36710463
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.NPSGroupNumber) 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.NPSGroupNumber) 1
val(gpval) 0  len(ListResult.NPSGroupNumber)1
val(gpval) 1  len(ListResult.NPSGroupNumber) 0
val(gpval)0  len(ListResult.NPSGroupNumber) 0


0
 
LVL 39

Expert Comment

by:gdemaria
ID: 36710568
> So if  #val(gpValue)# eq 1 and len(ListResult.NPSGroupNumber) 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.NPSGroupNumber) is any value
val(gpval) 1  and   len(ListResult.NPSGroupNumber) is 0
val(gpval) 1  and   len(ListResult.NPSGroupNumber) 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...


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Build PDF in coldfusion 2 63
Create array from a query and then loop it with coldfusion 12 67
CFMail not sending messages with queries 5 45
Problem with data displaying 2 22
This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

929 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

10 Experts available now in Live!

Get 1:1 Help Now