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

DispatchScriptRunner return values

Guide ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

Hi,

 

I expect this has been asked before, but I cannot find an answer on the forum.

 

I am using DispatchScriptRunner to call some jsx code. I would like the jsx code to return a value to my C plugin. A PMString would do. 

 

Thanks.

 

P.

TOPICS
SDK

Views

968

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

correct answers 1 Correct answer

Community Expert , Feb 03, 2020 Feb 03, 2020

Hi Pickory,

 

As Dirk_Becker rightly mentioned you will need to use the result param. In order to use it you will have to intepret the return data using the get functions of the ScriptData. Try the following to get a string value returned from your jsx code

ScriptRecordData arg;
ScriptData script;
IDFile f(PMString("Macintosh HD:Users:manan:Desktop:demo_script.jsx"));
script.SetFile(f);
ScriptData result;
PMString errorString;            
InterfacePtr<IScriptManager> scriptManager(Utils<IScriptU
...

Votes

Translate

Translate
Guide ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

Anything wrong with "@param result is the return value OUT" ?

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
Guide ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

Hi Dirk, 

 

Thank you. I am not sure how to access or set that from the script. So I have ended up using the passed paramters, like this.

 

Utils<IScriptArgs>()->Set(PMString("Param1"), "DoAction" ); 

Utils<IScriptUtils>()->DispatchScriptRunner ( .......

 

PMString pm;

pm = Utils<IScriptArgs>()->Get(PMString("Param1") );

 

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 ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

Hi Pickory,

 

As Dirk_Becker rightly mentioned you will need to use the result param. In order to use it you will have to intepret the return data using the get functions of the ScriptData. Try the following to get a string value returned from your jsx code

ScriptRecordData arg;
ScriptData script;
IDFile f(PMString("Macintosh HD:Users:manan:Desktop:demo_script.jsx"));
script.SetFile(f);
ScriptData result;
PMString errorString;            
InterfacePtr<IScriptManager> scriptManager(Utils<IScriptUtils>()->QueryScriptManager(kJavaScriptMgrBoss));
            InterfacePtr<IScriptRunner> scriptRunner(scriptManager, UseDefaultIID());
            Utils<IScriptUtils>()->DispatchScriptRunner( scriptRunner, script,
                                                        arg, result,
                                                        errorString, kTrue);
            PMString retval;
            result.GetPMString(retval);
            CAlert::InformationAlert(retval);

result will be populated by the value that you return from your jsx code, based on its type use the appropriate Get method and you should be good.

 

P.S. :- Have you been able to use DispatchScriptRunner command passing the script as a string, i am not able to do that. If you did please share your code snippet

 

-Manan 

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
Guide ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

LATEST

Hi Manan,

I am using a file with DispatchScriptRunner.

Your code works! Thank you.

My script was wrong. 

 

It is quite handy that you can set a named parameter from the script.

 

Dirk and Manan, both correct answers.

 

 

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