Recalling a form in Opus

I have a small VB script that invites the user to enter data. If that data does not meet the required criteria, currently the script tells the user and dumps them out of the script.

Ideally I would like to dump them out of the script and run the script again to give them another chance, but I am blowed if I can see how to do it.

Can any VB guru point me in the right direction. I would be very grateful.

Is this using a detached dialog? How are you getting the input from them? Is it a Script AddIn or a button script?

More info needed.

Your script can do whatever it wants. You can display the dialog a second time if you want to. You don't need to re-run the script; the script is still in control and can show more than one dialog, or the same dialog more than once, if it decides it needs to based on the initial inputs.

@Steve

It is a detached dialog. It is run from a button. As a starting point, I tried recalling the dialog, but appears then rapidly disappears. Ideally I would like the original dialog back so that the user can correct the error.

Thanks for your prompt responses.

I don't think you can reliably re-use the exact same dlg object, but you can create a second dlg object for the same dialog without any issues.

Example using a detached dialog:

function OnClick(clickData)
{
	for (var showCount = 0; showCount < 2; ++showCount)
	{
	    var Dlg = DOpus.Dlg;
	    Dlg.window = clickData.func.sourcetab;
	    Dlg.template = "dialog1";
	    Dlg.detach = true;
		Dlg.Create();

		var listview = Dlg.Control("listview1");
		var i = listview.AddItem("Line 1");
		listview.GetItemAt(i).subitems(0) = "L1.0";
		listview.GetItemAt(i).subitems(1) = "L1.1";
		i = listview.AddItem("Line 2");
		listview.GetItemAt(i).subitems(0) = "L2.0";
		listview.GetItemAt(i).subitems(1) = "L2.1";

	    Dlg.Show();
	    while (true)
		{
	        var Msg = Dlg.GetMsg();
	        if (!Msg.result) break;
	        DOpus.Output("Msg Event = " + Msg.event);
			if (Msg.event == "click" && Msg.control == "Autosize")
			{
				listview.columns.AutoSize();
			}
		}
	    DOpus.Output("Return code = " + Dlg.result);
    }
}
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>New Button</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>function OnClick(clickData)</instruction>
		<instruction>{</instruction>
		<instruction>	for (var showCount = 0; showCount &lt; 2; ++showCount)</instruction>
		<instruction>	{</instruction>
		<instruction>	    var Dlg = DOpus.Dlg;</instruction>
		<instruction>	    Dlg.window = clickData.func.sourcetab;</instruction>
		<instruction>	    Dlg.template = &quot;dialog1&quot;;</instruction>
		<instruction>	    Dlg.detach = true;</instruction>
		<instruction>		Dlg.Create();</instruction>
		<instruction />
		<instruction>		var listview = Dlg.Control(&quot;listview1&quot;);</instruction>
		<instruction>		var i = listview.AddItem(&quot;Line 1&quot;);</instruction>
		<instruction>		listview.GetItemAt(i).subitems(0) = &quot;L1.0&quot;;</instruction>
		<instruction>		listview.GetItemAt(i).subitems(1) = &quot;L1.1&quot;;</instruction>
		<instruction>		i = listview.AddItem(&quot;Line 2&quot;);</instruction>
		<instruction>		listview.GetItemAt(i).subitems(0) = &quot;L2.0&quot;;</instruction>
		<instruction>		listview.GetItemAt(i).subitems(1) = &quot;L2.1&quot;;</instruction>
		<instruction />
		<instruction>	    Dlg.Show();</instruction>
		<instruction>	    while (true)</instruction>
		<instruction>		{</instruction>
		<instruction>	        var Msg = Dlg.GetMsg();</instruction>
		<instruction>	        if (!Msg.result) break;</instruction>
		<instruction>	        DOpus.Output(&quot;Msg Event = &quot; + Msg.event);</instruction>
		<instruction>			if (Msg.event == &quot;click&quot; &amp;&amp; Msg.control == &quot;Autosize&quot;)</instruction>
		<instruction>			{</instruction>
		<instruction>				listview.columns.AutoSize();</instruction>
		<instruction>			}</instruction>
		<instruction>		}</instruction>
		<instruction>	    DOpus.Output(&quot;Return code = &quot; + Dlg.result);</instruction>
		<instruction>    }</instruction>
		<instruction>}</instruction>
		<instruction>==SCRIPT RESOURCES</instruction>
		<instruction>&lt;resources&gt;</instruction>
		<instruction>	&lt;resource name=&quot;dialog1&quot; type=&quot;dialog&quot;&gt;</instruction>
		<instruction>		&lt;dialog fontsize=&quot;8&quot; height=&quot;114&quot; lang=&quot;english&quot; resize=&quot;yes&quot; standard_buttons=&quot;cancel&quot; width=&quot;228&quot;&gt;</instruction>
		<instruction>			&lt;control height=&quot;84&quot; name=&quot;listview1&quot; nosortheader=&quot;yes&quot; resize=&quot;wh&quot; type=&quot;listview&quot; viewmode=&quot;details&quot; width=&quot;216&quot; x=&quot;6&quot; y=&quot;6&quot;&gt;</instruction>
		<instruction>				&lt;columns&gt;</instruction>
		<instruction>					&lt;item text=&quot;Test Column 1&quot; /&gt;</instruction>
		<instruction>					&lt;item text=&quot;Test Column 2&quot; /&gt;</instruction>
		<instruction>					&lt;item text=&quot;Test Column 3&quot; /&gt;</instruction>
		<instruction>				&lt;/columns&gt;</instruction>
		<instruction>			&lt;/control&gt;</instruction>
		<instruction>			&lt;control height=&quot;14&quot; name=&quot;Autosize&quot; resize=&quot;y&quot; title=&quot;Autosize&quot; type=&quot;button&quot; width=&quot;50&quot; x=&quot;6&quot; y=&quot;96&quot; /&gt;</instruction>
		<instruction>		&lt;/dialog&gt;</instruction>
		<instruction>	&lt;/resource&gt;</instruction>
		<instruction>&lt;/resources&gt;</instruction>
	</function>
</button>

Don’t close the dialog when the user clicks ok, just parse the entries and if they fail, clear the relevant edit boxes and prompt the user to explain whats gone wrong - leaving the dialog ready to retry perhaps.

Or use Leo’s solution.

2 Likes