Message box in script closes

Post here if you need help using Actiona
Post Reply
nickwiz
Posts: 2
Joined: 10 Mar 2018, 22:20

Message box in script closes

Post by nickwiz »

I have a Yes/No Message Box that asks a question.

If answer is Yes it calls a script that does some work with output to user. Then I want to make user confirm Yes/No that everything was OK. Here I open another MessageBox, but this time from script.

Problem is that actiona does not wait for the MessageBox to be closed. As of now this is at the end of my project, and the MessageBox does not show as the script finishes. If I add a "pause" after the call of the script that opens the MessageBox, it is shown, so the code works in itself.

How to make actiona wait for the MessageBox to be closed?

Sample code:

Code: Select all

function confirm() {
	var c = new MessageBox({
		title: "Press yes or no",
		icon: MessageBox.Warning,
		buttons: MessageBox.Yes | MessageBox.No,
		text: "Did cursor move to the correct positions?",
		onClose: function(e) {
			Console.print(e)
		}
	});
	c.show();
}

function validate() {
	var x, y, z;
        ...
}

if (validate) {
	validate_data();
	confirm();
}
francois
Posts: 456
Joined: 18 Oct 2010, 10:33
Location: France

Re: Message box in script closes

Post by francois »

Instead of show(), try showModal() and test the return code, example :

Code: Select all

var Boite = new MessageBox({
title: "title 1 ", 
text: "text_1", 
icon: MessageBox.Information, 
buttons: MessageBox.Yes | MessageBox.No
});

RC = Boite.showModal(); //

switch(RC){
case 65536 : 
    Console.print("11")
    Execution.stop();
    Break;
case 16384 : 
     Console.print("12");     
}
//=============

 
after_Boite = "text_2";


//=============
var Boite_2 = new MessageBox({
title: "title 2", // Titre
text:  "text_1" + " " + after_Boite  , // Texte
icon: MessageBox.Information, // Icône
buttons: MessageBox.Yes | MessageBox.No // Button
});


RC = Boite_2.showModal(); 
Console.print(RC)

switch(RC){
case  65536 : 
     Console.print("21") 
    Execution.stop();     
    Break;
case 16384 : 
     Console.print("22");
}
//=============


Console.print("99")
nickwiz
Posts: 2
Joined: 10 Mar 2018, 22:20

Re: Message box in script closes

Post by nickwiz »

Thanks a lot. Using showModal() works.

I also had a typo in my example as I wrote onClose: instead of onClosed:.

This works fine:

Code: Select all

function confirm() {
	var r, c = new MessageBox({
		title: "Press yes or no",
		icon: MessageBox.Question,
		buttons: MessageBox.Yes | MessageBox.No,
		text: "Did cursor move to the correct possitions?",
		onClosed: function(result) {
			Console.print(result);
			switch (result) {
			case MessageBox.Yes:
				Console.print("Yes");
				break;
			case MessageBox.No:
				Console.print("No");
				break;
			case 0:
				Console.print("Canceled");
				break;
			default:
				Console.print("... bug ? ...");		
			}
		}
	});
	r = c.showModal();
	Console.print("r=" + r);
}
Only one note: When closing the message-box using the window close button (x), the return from c.showModal() is not zero, as the documentation states, but MessageBox.No or 65536. I.e. it prints r=65536 from the example above.

The result variable from onClosed has the documented value. As in: MessageBox.Yes, MessageBox.No and zero when box is cancelled.
Post Reply