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

Using global variables across scripts

Community Beginner ,
Apr 17, 2013 Apr 17, 2013

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
2.0K
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

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

...
Translate
Enthusiast ,
Apr 17, 2013 Apr 17, 2013

insertLabel:

#target indesign

var objLabel = {

    house:'mouse'

    }

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

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

alert(currObj.house)

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

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

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

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
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
Guest
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 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.

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

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