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

cfinvoke returnvariable

Participant ,
Nov 26, 2012 Nov 26, 2012

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!

2.1K
Translate
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 ,
Nov 26, 2012 Nov 26, 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?

Translate
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 ,
Nov 26, 2012 Nov 26, 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")>

Translate
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 ,
Nov 26, 2012 Nov 26, 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. 

Translate
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 ,
Nov 27, 2012 Nov 27, 2012
LATEST

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]

Translate
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