Skip to main content
November 22, 2011
Question

How to get a value from JavaScript

  • November 22, 2011
  • 1 reply
  • 1603 views

How to get return value from Java Script and catch it in c++ code. I have tried following code, but its not working in my case.

what I want is if it returns true then call some function if it returns false then do nothing, so how to get those values in c++

ScriptData::ScriptDataType fDataType = resultData.GetType();

if (fDataType == kTrue)

                    {

       CAlert::InformationAlert("sucess");

       //call some function

                    }

                    else

                    {

                              CAlert::InformationAlert("Error");

     // do nothing

                    }

JavaScript Code:

    if(app.scriptArgs.isDefined("paramkeyname1"))

       {

           var value = app.scriptArgs.get("paramkeyname1");

           alert(value);

            return true;

       }

  else

       {

           alert ("SORRY");

           return false;

       }

This topic has been closed for replies.

1 reply

Jack_Ian
Known Participant
November 22, 2011

Just off the top of my head. Haven't tried this, but how about...

ScriptData::ScriptDataType fDataType = resultData.GetType();

bool16 JSResult = kFalse;          // Where JavaScript result is stored

ErrorCode EverythingOK = kFailure;

if (ScriptData::s_boolean == fDataType)          // Putting the constant on the left has saved me sooo many times where I typed "=" instead of "=="

{

     EverythingOK = resultData.GetBoolean(&JSResult)

}

November 22, 2011

How to get java script result into JSResult i m not getting it.

I have wriiten follwing code in c++ :

          WideString scriptPath("\\InDesign\\Source1.jsx");

          IDFile scriptFile(scriptPath);

          InterfacePtr<IScriptRunner>scriptRunner(Utils<IScriptUtils>()->QueryScriptRunner(scriptFile));

          if(scriptRunner)

          {

                    ScriptRecordData arguments;

                    ScriptIDValuePair arg;

                    ScriptID aID;

                    ScriptData script(scriptFile);

                    ScriptData resultData;

                    PMString errorString;

                    KeyValuePair<ScriptID,ScriptData> ScriptIDValuePair(aID,script);

                    arguments.push_back(ScriptIDValuePair);

                    PMString paramkeyname1;

                    Utils<IScriptArgs>()->Save();

                    Utils<IScriptArgs>()->Set("paramkeyname1",scriptPath);

                    Utils<IScriptUtils>()->DispatchScriptRunner(scriptRunner,script,arguments,resultData,errorString,kFalse);

                    Utils<IScriptArgs>()->Restore();

                    ScriptData::ScriptDataType fDataType = resultData.GetType(); // here i should get true or false which i m passing it from javascript code......not as s_boolean

                    if (fDataType == kTrue)

                    {

                                   //CAlert::InformationAlert("sucess");

                                 iOrigActionComponent->DoAction(ac, actionID, mousePoint, widget);

                    }

                    else

                    {

                                this->PreProcess(PMString(kCstAFltAboutBoxStringKey));

                    }

          }

Java script code:

function main()

{

       var scrpt_var;

       var scriptPath,scrptMsg;

       var frntDoc=app.documents[0];

       if(app.scriptArgs.isDefined("paramkeyname1"))

       {

           var value = app.scriptArgs.get("paramkeyname1");

            alert(value);

             return true; // i want this value i should get in c++ code...How to get these values in c++

       }

       else

       {

          alert ("Error");

          return false; // i want this value i should get in c++ code...How to get these values in c++

       }

}

Participating Frequently
December 17, 2013

I have the Exactly same problem.

I can't find anywhere how to got the JS return.

I just need to get true or false.

Any help would be appreciated.