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.
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
...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)
Copy link to clipboard
Copied
what hans said, and also, i think global variables are persistent in the same target engine
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
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.
Copy link to clipboard
Copied
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.