Hello!
We have an interactive Automation script (BroadpeakSwitch) that works correctly when executed manually from DataMiner Cube, but fails when launched from a Low-Code App with the following error:
"Encountered errors while executing script: Error launching script: interaction is required to execute this script"
The full script is attached for your analysis. Could you please help us understand the cause of this error?
Thank you in advance.
Best regards,
Script:
namespace BroadpeakSwitch
{
public class Script
{
public void Run(IEngine engine)
{
try
{
//engine.ShowUI();
RunSafe(engine);
}
catch (Exception e)
{
engine.ExitFail($"Run|Something went wrong: {e.Message}");
}
}
private static void RunSafe(IEngine engine)
{
engine.SetFlag(RunTimeFlags.NoKeyCaching);
engine.Timeout = TimeSpan.FromHours(1);
....
var app = new InteractiveController(engine);
var navigation = new NavigationService(app, engine, switchService, request);
navigation.Start(channels);
}
}
....
public class NavigationService
{
private readonly InteractiveController _app;
private readonly IEngine _engine;
private readonly SwitchService _switchService;
private readonly SwitchRequest _request;
public NavigationService(InteractiveController app, IEngine engine, SwitchService switchService, SwitchRequest request)
{
_app = app;
_engine = engine;
_switchService = switchService;
_request = request;
}
public void Start(IList<Channel> channels)
{
var dialog = new ConfirmationDialog(_engine, this, _switchService.ElementName, _request, channels);
_app.ShowDialog(dialog);
}
public void ExecuteSwitch(IList<Channel> channels)
{
var result = _switchService.Execute(channels, _request.InputSource);
_app.ShowDialog(new ResultDialog(_engine, this, result));
}
public void CloseApp(string message) => _engine.ExitSuccess(message);
}
/// <summary>
/// Mostra o que os parâmetros pediram e aguarda confirmação. Não permite alterar a escolha.
/// </summary>
public class ConfirmationDialog : Dialog
{
private readonly Label _title = new Label("Confirm Switch") { Style = TextStyle.Title };
private readonly TextBox _channelsBox = new TextBox { IsMultiline = true, Height = 150, Width = 400, IsReadOnly = true };
private readonly Button _btnCancel = new Button("Cancel") { Width = 120 };
private readonly Button _btnConfirm = new Button("Confirm") { Width = 120 };
public ConfirmationDialog(IEngine engine, NavigationService nav, string elementName, SwitchRequest request, IList<Channel> channels) : base(engine)
{
Title = "Broadpeak - Confirm";
string scope = request.IsAllChannels
? $"All channels ({channels.Count})"
: $"Single channel: {channels[0].Name}";
_channelsBox.Text = string.Join(Environment.NewLine, channels.Select(c => c.Name));
AddWidget(_title, 0, 0, 1, 2);
AddWidget(new Label("Element:"), 1, 0);
AddWidget(new Label(elementName) { Style = TextStyle.Bold }, 1, 1);
AddWidget(new Label("Scope:"), 2, 0);
AddWidget(new Label(scope) { Style = TextStyle.Bold }, 2, 1);
AddWidget(new Label("Target source:"), 3, 0);
AddWidget(new Label(request.InputSource.ToUpperInvariant()) { Style = TextStyle.Bold }, 3, 1);
int row = 4;
if (request.IsAllChannels)
{
AddWidget(new Label("Affected channels:"), row++, 0, 1, 2);
AddWidget(_channelsBox, row++, 0, 1, 2);
}
AddWidget(_btnCancel, row, 0);
AddWidget(_btnConfirm, row, 1);
_btnCancel.Pressed += (s, e) => nav.CloseApp("Switch cancelled by the user.");
_btnConfirm.Pressed += (s, e) => nav.ExecuteSwitch(channels);
}
}
public class ResultDialog : Dialog
{
private readonly Label _title = new Label("Operation Result") { Style = TextStyle.Title };
private readonly Label _summary = new Label();
private readonly TextBox _errorBox = new TextBox { IsMultiline = true, Height = 200, Width = 400, IsReadOnly = true };
private readonly Button _btnClose = new Button("Finish") { Width = 120 };
public ResultDialog(IEngine engine, NavigationService nav, SwitchResult result) : base(engine)
{
Title = "Broadpeak - Result";
int successCount = result.Succeeded.Count;
int errorCount = result.Errors.Count;
_summary.Text = $"Target: {result.InputSource} | Success: {successCount} channel(s) | Errors: {errorCount}";
AddWidget(_title, 0, 0, 1, 2);
AddWidget(_summary, 1, 0, 1, 2);
int row = 2;
if (errorCount > 0)
{
_errorBox.Text = string.Join(Environment.NewLine, result.Errors);
AddWidget(new Label("Error Logs:"), row++, 0, 1, 2);
AddWidget(_errorBox, row++, 0, 1, 2);
}
AddWidget(_btnClose, row, 1);
_btnClose.Pressed += (s, e) => nav.CloseApp(
$"Switch to {result.InputSource} finished: {successCount} succeeded, {errorCount} failed.");
}
}
}
Hi Maximiliano
From the code excerpt, it does indeed appear that the script is intended to be recognized as interactive. The reported launch error suggests that the Low-Code App may not be treating the script it starts as interactive, but the excerpt alone does not show why. Could you check that the Low-Code App references BroadpeakSwitch itself, rather than a different script or a wrapper script?
It is recommended to use the XML Interactivity setting, which is supported from DataMiner 10.5.9/10.6.0 onward. If your version supports it, add <Interactivity>Always</Interactivity> next to the <Name> element. Setting it explicitly is preferable to relying on the //engine.ShowUI(); hint comment. On older versions, the setting is not supported and automatic detection is used.
Let me know how it goes.
Kind regards