Skip to main content
Inspiring
November 26, 2012
Question

cfinvoke returnvariable

  • November 26, 2012
  • 2 replies
  • 2259 views

I'm not completely clear on how cfinvoke works.

Am I using the returnvariable correctly with this cfinvoke? 

Would the variable scope name be the returnvariable name? 

Is it returned parsed?

Can the return value come back to the same page that had the cfinvoke on it or should it be a separate page?

<cfinvoke component="#PaymentGateway#" method="createSubscription" returnvariable="result">

<cfoutput>#result.resultcode#</cfoutput>

Thanks!

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    November 27, 2012

    Balddog4 wrote:

    Would the variable scope name be the returnvariable name?  

    <cfinvoke component="#PaymentGateway#" method="createSubscription" returnvariable="result">

    <cfoutput>#result.resultcode#</cfoutput>

    By default, ColdFusion stores the return variable in the variables scope of the calling page. You can verify this yourself with <cfdump var="#variables#">.

    Just another point. Your code suggests that the method createSubscription returns a structure. Usually, I formally declare the type of the return variable, particularly when it is a complex variable like struct, array, query, object and so on.

    <cfset returnVar = structNew()>

    <cfinvoke returnvariable="result">

    <cfset returnVar = duplicate(result)>

    Alternatively, you could just add a comment that says that the return variable is a struct. This eases code understanding especially when there is a lot of other business on the calling page.

    [Edited]

    Inspiring
    November 27, 2012

    The return value has to come back to the page that called the cfinvoke.  That's quite simply how it works.

    The variable scope name would indeed be the return variable name.

    Your sample code looks ok if PaymentGateway is a variable.  If it's the name of your cfc, lose the octothorps.  What happens when you run it?

    Inspiring
    November 27, 2012

    Thank you so much for responding.  I don't use this often enough to get comfortable coding it.

    I haven't run it yet.  I'll have access to the server in the morning, so I was trying to prepare.

    This part goes before the cfinvoke:

    <cfset PaymentGateway = CreateObject("component","AuthorizeNetRecurring").init(

    loginname = "#GetGateway.Login#",

    transactionKey = "#GetGateway.Tran_key#",

    mode = "live")>

    Inspiring
    November 27, 2012

    Not exactly.  Once you use CreateObject or <cfobject> to create a variable, you call the method directly.  Going back to your original post, you would do this:

    <cfset result = PaymentGateway.createSubscription()>

    In fact, since you had to provide two arguments to the init() method of the cfc, using cfinvoke would not work in this situation.