• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

i need solution for this?

New Here ,
May 28, 2010 May 28, 2010

Copy link to clipboard

Copied

hi friends,

           i got error this program

lo.cfc

cfcomponent>

<cffunction  name="logon1" access="remote" returntype="Any" >

<cfargument name="from_where" type="string" required="true" >

<cfset form.from_where=from_where>

<cfparam name="client.sec_user_id" default="">
        <cfparam name="client.org_focus" default="">

        <cfquery name="close_record" Datasource="#request.ds.auth#">
            UPDATE    logon_activity_track
            SET        record_closed = 1
            WHERE    (cfid = '#client.cfid#:#client.cftoken#' and
                    app = '#application.applicationname#' and
                    sec_user_id = #val(client.sec_user_id)# and
                    sec_organization_id = #val(client.org_focus)# and
                    def_system_id = #application.sys.def_system_id# and
                    record_closed = 0)
        </cfquery>

        <cfset client.vl = "">
        <cfset client.suag = "">       
        <cfset client.sec_user_id = "">
        <cfset client.sec_organization_id = "">
        <cfset w = structdelete(session,"ap")>

</cffunction>

</cfcomponent>

result2.cfm

<cfobject name="TestObject1" component="IST_Business_Applications.IST_Docstor.file_access.lo" >


<cfset a=TestObject1.logon1("logout")>
<cfoutput >
         #a#
</cfoutput>

i got undefined a error is coming

anybody give solution

TOPICS
Builder

Views

932

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 28, 2010 May 28, 2010

Copy link to clipboard

Copied

Your function doesn't return anything, so - indeed - your variable "a" will be undefined.

I think you should read up on code encapsulation, btw.  You're using an awful lot of external variables in the function, which is pretty poor practice.  Other than in extreme circumstances, a function should only deal with variables it has passed in as arguments, and other variables in itself creates.  It should not access external variables (like stuff in the client, session, form and request scope, like you're doing).

You should also parametrise your query, rather than hard-coding your variables into it.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 28, 2010 May 28, 2010

Copy link to clipboard

Copied

I think Adam is talking about doing something like this, which is more in line with best programing practices. It's also a good idea to name-scope your variables within the component:

o.cfc

cfcomponent>

<cffunction  name="logon1" access="remote" returntype="struct" >

<cfargument name="from_where" type="string" required="true" >

<cfargument name="varsClient" type="struct" required="true" >

<cfargument name="appName" type="struct" required="true" >

<cfset form.from_where=from_where>

        <cfset loStruct = structNew()>

        <cfparam name="loStruct.sec_user_id" default="">
        <cfparam name="loStruct.org_focus" default="">

        <cfquery name="close_record" Datasource="#request.ds.auth#">
            UPDATE    logon_activity_track
            SET        record_closed = 1
            WHERE    (cfid = '#arguments.varsClient.cfid#:#arguments.varsClient.cftoken#' and

                    app = '#arguments.appname#' and
                    sec_user_id = #val(arguments.varsClient.sec_user_id)# and

                    sec_organization_id = #val(arguments..varsClient.org_focus)#  and

                    record_closed = 0)
        </cfquery>

        <cfset arguments.varsClient.vl = "">

        <cfset arguments.varsClient.suag = "">       

        <cfset arguments.varsClient.sec_user_id = "">

        <cfset arguments.varsClient.sec_organization_id = "">        

       <cfreturn varsClient />

</cffunction>

</cfcomponent>

result2.cfm

<cfobject name="TestObject1" component="IST_Business_Applications.IST_Docstor.file_access.lo" >


<cfset a=TestObject1.logon1("logout", varsClient = client, appName = application.applicationName)>

<cfset w = structdelete(session,"ap")>

<cfdump var="#a#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 28, 2010 May 28, 2010

Copy link to clipboard

Copied

Yeah, something along those lines.  lthough make sure you VAR scope your local variables in your function, ie: loStruct and close_record.

That said, close_record is actually redundant here, because UPDATE queries don't return anything.  One might as well not bother specifying a NAME attribute in these cases.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 28, 2010 May 28, 2010

Copy link to clipboard

Copied

Good point on everything....

Just one question from me: I've always wondered the benefits of using the VAR scope in the component.

What is the main reason for doing that?

Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 28, 2010 May 28, 2010

Copy link to clipboard

Copied

Spider:

The VAR kewyword is used in any UDF – not just in CFCs – to make that variable local to the function being defined. This avoids name interference when you have a variable with the same name in the template using the UDF.

Note that you have to give these VARs a value, e.g. there must be a = in there. This
<cfset var someName> is not valid. You can do
<cfset var someName = “”>
and later in the function change that “” to a real value.

HTH,

Carlos

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 28, 2010 May 28, 2010

Copy link to clipboard

Copied

Spider, you may want to check out this blog entry, which points to several resources that address your very question ("why should I worry about VAR scoping?"):

The Ultimate Var Scope Resource list? Understanding/resolving problems with the var scope in CFML

http://www.carehart.org/blog/client/index.cfm/2010/3/4/resources_on_the_var_scope_problem

That said, none of this thread has been about CFBuilder, specifically.

To @welcomecan, your question really should have been directed to the general Adobe CF support forum (http://forums.adobe.com/community/coldfusion/coldfusion_general). FWIW, there are still others as well, which I point out it here:

CFML Lists and Forums (finding help and support)

http://www.cf411.com/#cflists

Hope that's helpful.

/charlie


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 01, 2010 Jun 01, 2010

Copy link to clipboard

Copied

Thanks for the link to this page... it is VERY useful. Looking at some of those articles, I can see what might be causing some mysterious CFTHREAD issues... good stuff.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 30, 2010 May 30, 2010

Copy link to clipboard

Copied

hi spider,

Thanks for ur reply.i used that program . now i got a error this line.

<cfset a=TestObject1.logon1("logout", varsClient = client, appName = application.applicationName)>

Invalid CFML construct found

give solution.

regards

welcomecanv

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 01, 2010 Jun 01, 2010

Copy link to clipboard

Copied

LATEST

Hi,

Please try explicitly naming all the variables being passed into the CFC:

For example,

<cfset a=TestObject1.logon1( variableName = "logout", varsClient = client, appName = application.applicationName)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation