When I have an automation script that launches another sub automation script, can I pass/return data from my sub script to my 'parent' script? E.g. in case there's an exception in the subscript.
Hi Jochen, when running an automation script as subscript you can return data to the main script via the AddScriptOutput.
Here an example of how I use it:
Subscript:
// Add data to be returned to main script.
engine.AddScriptOutput("PlmStorageJson", storageJson);
engine.AddScriptOutput("PlmError", error);
Mainscript:
var scriptOptions = _engine.PrepareSubScript("SLC_DOM Get Storage Data");
...
scriptOptions.StartScript();
Dictionary<string, string> result = scriptOptions.GetScriptResult();
string plmError = string.Empty;
string plmStorageJson = string.Empty;
result.TryGetValue("PlmError", out plmError);
result.TryGetValue("PlmStorageJson", out plmStorageJson);
A video explaining this is also available in the Automation course: https://community.dataminer.services/lessons/subscript-results/
Hi,
To emphasize the answer of Mieke:
A request is sent to the server for starting an Automation script.
When that script is finished/completed, then a response is sent back, namely 'ExecuteScriptResponseMessage'.
Such response message has a property called 'ScriptOutput':
So it can not only used for communications between scripts, but it can also be used to communicate to the 'executioner' of the script.
Otherwise said: you can actually use scripts now as functions: you start with given arguments (dummies, parameters, memory files) and you end with return values.
A nice example in Cube is the 'Automation script session variables' feature (RN 27895).
If both scripts would need to be started from a visual overview, it is also possible to store the info in session variables by using the "AddScriptOutput" function like this:
engine.AddScriptOutput(UIVariables.VisualOverview.CreateKey("MyOutput"), "myValue");
That's typically done by using a 'memory' in Automation I believe, where you store data with one script and access it with another. Or are there other ways?
Exactly what I needed, thanks!