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

Using global variables across scripts

Community Beginner ,
Apr 17, 2013 Apr 17, 2013

Copy link to clipboard

Copied

Hi,

I have a SOAP client which executes runScript method.

Three SOAP requests, one after the other, call runScript and execute a corresponding jsx on server.

Can I have some session/global-wide variables that I can access across scripts?

For example, during execution of first script, I set some variable. And again during the second and third SOAP requests, I use the variable (set in 1st script) in the 2nd and 3rd scripts.

 

How can I achieve the above?

I would really appreciate some help on this.

TOPICS
Scripting

Views

1.8K

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

Deleted User
May 02, 2013 May 02, 2013

You can use either of the methods #targetengine or insertLabel.

One demerit, I would say, of #targetengine "session01" is that the specific session will exists as long as InDesign is running, which is not desirable. Those will destroy only when you quit your application. I don't think there is any garbage collection to rescue here.

However, insertLabel and extractLabel can be used on specifc DOM objects, as per your need, including the app object.

If you want to share variables across scripts on pe

...

Votes

Translate

Translate
Enthusiast ,
Apr 17, 2013 Apr 17, 2013

Copy link to clipboard

Copied

insertLabel:

#target indesign

var objLabel = {

    house:'mouse'

    }

app.insertLabel('appLabel', objLabel.toSource());

var currObj = eval(app.extractLabel('appLabel'));

alert(currObj.house)

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
Advisor ,
Apr 17, 2013 Apr 17, 2013

Copy link to clipboard

Copied

what hans said, and also, i think global variables are persistent in the same target engine

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
Explorer ,
Apr 17, 2013 Apr 17, 2013

Copy link to clipboard

Copied

Fo exchanging values between scripts you can make use of a targetengine.

Script one

      #targetengine "session01"
  var myValue = 0; // new value
      alert(myValue); // result is 0
      myValue++; // increment by 1

Script two

      #targetengine "session01"
    alert(myValue); // result is 1

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
Guest
May 02, 2013 May 02, 2013

Copy link to clipboard

Copied

You can use either of the methods #targetengine or insertLabel.

One demerit, I would say, of #targetengine "session01" is that the specific session will exists as long as InDesign is running, which is not desirable. Those will destroy only when you quit your application. I don't think there is any garbage collection to rescue here.

However, insertLabel and extractLabel can be used on specifc DOM objects, as per your need, including the app object.

If you want to share variables across scripts on per-document basis then you can store the variables on the document object:

doc.insertLabel("name", "value");

So, once the document is closed all the labels are gone. You can decide according to your requirement whether you want application-level globals (then use app.insertLabel), document level (then doc.insertLabel), spread level, etc.

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
Advisor ,
May 02, 2013 May 02, 2013

Copy link to clipboard

Copied

LATEST

if you use the insert/extract label, you can use myObject.toString() to serialize an entire object, and when you retrive the label use myObject=eval(myLabelString). The same trick is usefull to store script preferences.

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