Skip to main content
Participant
May 28, 2010
Question

i need solution for this?

  • May 28, 2010
  • 2 replies
  • 1240 views

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

This topic has been closed for replies.

2 replies

Inspiring
May 28, 2010

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#">

Inspiring
May 28, 2010

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

Inspiring
May 28, 2010

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.

Inspiring
May 28, 2010

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