?
Solved

cfif inside a function

Posted on 2003-03-18
6
Medium Priority
?
951 Views
Last Modified: 2013-12-24
i am getting an error message , can i put cfif inside a function tag? liek this?

<CFCOMPONENT>
     
     <CFFUNCTION access="remote" name="list_vendors" returntype="string" hint="Getting the list of vendors">
               <CFIF IsUserInRole  ("Global") >
            <!--- if this is a manager --->
          <CFSET Contactid = ListFirst(GetAuthUser())>
          <CFSET manager = ListRest(GetAuthUser())>
          <CFQUERY NAME="get_vendors" DATASOURCE="techteams" DBTYPE="ODBC">
               SELECT DISTINCT Vendor_Name FROM qry_screen_output
               WHERE UserRoleName = '#manager#'
               Order by Vendor_Name
          </CFQUERY>
           <CFSET vendors = Valuelist(get_vendors.Vendor_Name)>
          <CFRETURN vendors>
           
            <CFELSE>
            <!--- NOT GLOBAL  --->
          <CFSET Contactid = ListFirst(GetAuthUser())>
          <CFSET acronymn = ListRest(GetAuthUser())>
          <CFQUERY NAME="get_vendors" DATASOURCE="techteams" DBTYPE="ODBC">
               SELECT DISTINCT Vendor_Name FROM qry_screen_output
               WHERE ContactID = #Contactid#
               Order by Vendor_Name
          </CFQUERY>
           
           
          <CFSET vendors = Valuelist(get_vendors.Vendor_Name)>
          <CFRETURN vendors>
            </CFIF> <!--- IF USER IN ROLE  --->
     </CFFUNCTION>
0
Comment
Question by:finnstone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 

Author Comment

by:finnstone
ID: 8161704
i am calling the above cfc (i didnt forget the compenent tag just left it out when copying) with the below code

<cfinvoke component="productdetails" method="list_vendors" returnVariable="vendors">
     
</CFINVOKE>


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<CFOUTPUT>
<b>#vendors#</b>
</cfoutput>
</body>
</html>
0
 

Author Comment

by:finnstone
ID: 8161708
I get the following error !


Context validation error for tag CFARGUMENT.  
The tag must be nested inside a CFFUNCTION tag.  
 
The Error Occurred in C:\CFusionMX\wwwroot\TechTeams\productdetails.cfc: line 37
 
35 :      <CFFUNCTION access="remote" name="list_accounts" returntype="string" hint="Getting the list of accounts">
36 :           <CFIF IsUserInRole  ("Global") >
37 :             <CFARGUMENT name="selVendor" type="string" required="true">    
38 :           <CFSET selVendor = ListQualify(selVendor,"'",",")>
39 :             <CFSET Contactid = ListFirst(GetAuthUser())>

 
0
 
LVL 1

Expert Comment

by:JUSTICE
ID: 8166484
I usually get around these problems by using <cfinclude template="file1.cfm"> inside of my if statement.
 
35 :      <CFFUNCTION access="remote" name="list_accounts" returntype="string" hint="Getting the list of accounts">
36 :           <CFIF IsUserInRole  ("Global") >
37 :             <cfinclude template="IfFile.cfm">    
38 :          
39 :             <cfelse>
40 :              <cfinclude template="IfFile2.cfm">
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 

Author Comment

by:finnstone
ID: 8167547
Can i invoke a cfm from inside a cfc ? I tried and it doesnt seem to be working.

Also this was kind of an annoying approach because i had to create 6 new cfms - i had 3 functions and and if statement for each function
0
 
LVL 1

Accepted Solution

by:
JUSTICE earned 600 total points
ID: 8167737
well, I think the problem is that you are defining your CFARGUMENTS inside of the IF statement.  If you can get the argument moved outside of the if statement, then it wont have a problem, or better yet, create 4 seperate <CFFUNCTIONS inside that CFC and put the IF statement in your main page, and then call whatever component applies.  does that make sense??

Because when your component tries to execute, the IF statement has not been decided yet, and it thinks there are no arguments to your component.  Then, after it evaluates the IF, it see's an argument, and throws an error.
0
 

Author Comment

by:finnstone
ID: 8167881
ok i got the first function to work using your method..however i cannot get the second one to work.

Answer this question

if i have this

     <CFFUNCTION access="remote" name="list_accounts" returntype="string" hint="Getting the list of accounts">
          <CFARGUMENT name="selVendor" type="string" required="true">  

how can i refer to selVendor in another cfm

can i set it in cfm doing this

cfset selVendor = '#list_accounts.selVendor#'???


***************88



<CFCOMPONENT>
     
     <CFFUNCTION access="remote" name="list_vendors" returntype="string" hint="Getting the list of vendors">
               <CFIF IsUserInRole  ("Global") >
               <cfinclude template="Global1.cfm">    

           
            <CFELSE> <!--- NOT GLOBAL  --->
            <cfinclude template="NonGlobal1.cfm">    
           

            </CFIF> <!--- IF USER IN ROLE  --->
            <CFRETURN vendors>
     </CFFUNCTION>
       
         
     
      <!--- GLOBAL  --->
     <CFFUNCTION access="remote" name="list_accounts" returntype="string" hint="Getting the list of accounts">
          <CFARGUMENT name="selVendor" type="string" required="true">  
            <CFIF IsUserInRole  ("Global") >
            <cfinclude template="Global2.cfm">
0

Featured Post

Simple, centralized multimedia control

Watch and learn to see how ATEN provided an easy and effective way for three jointly-owned pubs to control the 60 televisions located across their three venues utilizing the ATEN Control System, Modular Matrix Switch and HDBaseT extenders.

Question has a verified solution.

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

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

800 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