Hi all
I have an AS script that expose a URL as result in a UI popup, as the script is executed inside the LCA
UIBuilder uib = new UIBuilder();
UIBlockDefinition link = new UIBlockDefinition();
link.Type = UIBlockType.DownloadButton;
link.ConfigOptions = new AutomationDownloadButtonOptions()
{
Url = "https://url",
StartDownloadImmediately = false,
FileNameToSave = "",
ReturnWhenDownloadIsStarted = true,
};
link.Title = "link";
uib.AppendBlock(link);
UIResults res = new UIResults();
do
{
res = engine.ShowUI(uib);
} while (!res.WasOnDownloadStarted("link"));
I setted the url as Download button so the user is able to click on it and the new webpage will be opened, I also need to add the do block so the popup stay opened so the user can click on it.
But how I can let the popup auto-close when the download start? I tried with WasOnDownloadStarted but it not works
Hi Marco,
You will need to set a destination variable on your UI component.
In your use case, please set destination variable of UIBlockDefinition link:
link.DestVar = "link";
Also, you need to update he builder so it can receive responses:
uib.RequireResponse = true;
Then it should work if you do not touch the condition in the while loop.
More info:
- Property DestVar | DataMiner Docs
- Method WasOnDownloadStarted | DataMiner Docs
Hope this helps you further.
Looking forward to your positive reply.
Note: if things work, then you could then change you while loop from hardcoded "link" to link.DestVar.
Hi Marco
It should be possible to stop the script when the download button was clicked. The script you've added would need a few changes though.
The identifier of a block definition, that you're using in WasOnDownloadStarted, is stored in the DestVar property, instead of Title. Next to that the RequireResponse property should be set to true, otherwise the script will constantly loop and refresh the UI.
Could you update the script as follows and let me know if this works for you?
UIBuilder uib = new UIBuilder();
uib.RequireResponse = true;
UIBlockDefinition link = new UIBlockDefinition();
link.DestVar = "link";
// …
Small note: the URL will need to remain available after the script was stopped, because the download could still be busy. For instance, for a file located in the Documents module.