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

x
?
Solved

cfif inside a function

Posted on 2003-03-18
6
Medium Priority
?
973 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
  • 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
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 

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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

581 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