Skip to main content
Known Participant
December 19, 2011
Answered

[JS CS4/CS5/CS5.5] How to get return value from Javascript when using doScript

  • December 19, 2011
  • 2 replies
  • 929 views

Hi all

I'm trying to call some javascript from COM (c#) and this works fine. Passing parameters to the javascript and reading them using the arguments syntax also works fine.

What I can't seem to get to work is how to pass something back from the javascript to the calling COM invoker, in this case c#. How/where do I place the return value in the javascript?

Thanks in advance.

Ruvan

This topic has been closed for replies.
Correct answer John Hawkinson

doScript() is evaluating an expression, so just ensure that your Javascript is an expression.

For instance "(3+3)" will return 6.

2 replies

Inspiring
December 20, 2011

I might add that if the script you're calling is a stand-alone script file (with a global context that can't explicitly return anything) rather than a function or a JavaScript expression in a string, the return value will be the last value in the called script. So if your doScript() looks like this:

app.doScript(File("/path/to/script.jsx"), ScriptLanguage.JAVASCRIPT);

Then script.jsx can return a value like this:

var returnValue = null;

//...stuff that modifies returnValue

returnValue;

Jeff

John Hawkinson
John HawkinsonCorrect answer
Inspiring
December 20, 2011

doScript() is evaluating an expression, so just ensure that your Javascript is an expression.

For instance "(3+3)" will return 6.