I want to start a subscript to gather info from a system that is accessible only from a given agent.
Can I specify on what agent an automation subscript is being run?
Hi Hans,
Based on the comment question " how to retrieve data reported back from a script started in this way ??"
The ExecuteScriptResponseMessage and the ScriptProgressEventMessage has a property called ScriptOutput. This is a key-value pair dictionary.
More info on ScriptOutput: https://docs.dataminer.services/develop/api/types/Skyline.DataMiner.Net.Messages.ExecuteScriptResponseMessage.html#Skyline_DataMiner_Net_Messages_ExecuteScriptResponseMessage_ScriptOutput
Note that the message must be sent synchronously. Therefore, the DEFER option must be set to false.
More info: https://docs.dataminer.services/develop/api/types/Skyline.DataMiner.Net.Messages.ExecuteScriptMessage.html?q=ExecuteScriptMessage
You can use the Engine class to fill in the script values (in the subscript code).
Possible methods are: GetScriptOutput(string key), AddOrUpdateScriptOutput(string key, string value), AddScriptOutput(string key, string value), ClearScriptOutput(string key), ..
Pseudo-code 1 (SLNet call):
var scriptMessage = new ExecuteScriptMessage()
{
DataMinerID = myDMAID,
ScriptName = "myScript",
//execute the script synchronously
Options = new SA(new[] { $"DEFER:{bool.FalseString}" }),
};
var response = Engine.SLNet.SendSingleResponseMessage(scriptMessage) as ExecuteScriptResponseMessage;var scriptResult = response?.ScriptOutput;
Pseudo code 2 (Engine):
var scriptOptions = engine.PrepareSubScript("myScript");
// Following option is not needed by default, but can be useful: "indicating whether the script output of the subscript merges the full script output of the current running script."
//scriptOptions.InheritScriptOutput = true;
scriptOptions.StartScript();
Dictionary<string, string> result = scriptOptions.GetScriptResult();
Hi Hans,
Do mind this is pseudo code for pure illustration.
To fix your issue, you must cast the response to the correct message.
“var response = Engine.SLNet.SendSingleResponseMessage(scriptMessage) as ExecuteScriptResponseMessage;”
DMSMessage is the base message for messages.
I’ve updated the pseudo code accordingly.
Thanks for the clarification Matthias.
I am now able to run the script on the specified agent.
However I did not succeed to read back results.
When I us ethe second method (and start the main script on the correct agent) then I do get results back.
Is any specific option to be declared additionally (such as in the conventional method: .InheritScriptOutput=true ??
Hi Hans,
Now you’ve mentioned it, there is an option that needs to be set.
The script messages are executed asynchronously. so this means that response will not have the stored values. In order to have the values, you must fill in the Defer option to false. Setting the option to false will execute the script synchronously. I’ve updated the pseudo code on how to do this.
I do hope everything works fine and is described clearly.
If so, please do mark this question as resolved by selecting this answer as top answer (top-left corner of this answer section).
Hi Hans,
I believe there is already a similar question:
Thanks a lot.
That is indeed what I was looking for.
Just one more question: how to retrieve data reported back from a script started in this way ??
Hi Hans,
I’ve replied your question in a separate answer section, to make it clear to you and the other s+ the benefits of using hyperlinks and code blocks.
Thanks’ for your feedback MAthias.
Unfortunately I can not make it work yet..
Using your first pseudo code pops up an error…
My trial code:
var scriptMessage = new ExecuteScriptMessage()
{
DataMinerID = 1226,
ScriptName = “DRM_reading_VMX_ContentIds”
};
var response = Engine.SLNet.SendSingleResponseMessage(scriptMessage);
var scriptResult = response?.ScriptOutput;
but the validation test reports: DMSMessage does not contain a definition for .ScriptOutput…
And your second sample works but here I am unable to specify the subscript should run an a specific agent…