cancel
Showing results for 
Search instead for 
Did you mean: 

Within a C# Unity script, how can I present the user with a MessageBox and capture a DialogResult?

Sam_Walker
Confirmed Champ
Confirmed Champ

Quoting the accepted answer on this post (https://www.onbase.com/community/technical_communities/onbase_apis/f/10815/t/21344😞

Unity API scripting is available either through C# or VB.NET, and you can refererence libraries such as System.Windows.Forms so displaying a message box or even more intricate UI is no problem.

I have attempted to write a C# Unity script that would launch when the user clicks an Action Button, display a MessageBox to the user, allow them to press Yes or No, then capture that result, and perform certain actions based on which button was clicked.

I have added a reference to System.Windows.Forms to my script and my code is below, which compiles without errors.

When I click the Action Button, the script launches, but the message box with Yes/No never appears. The message box that appears says "You did not click Yes or No." As you can see in my code below, that one pops up if we do not detect a valid DialogResult.

I will note that I have tried all the different values for the MessageBoxOptions parameter, without success.

public void OnWorkViewExecuteActionButtonScript(Hyland.Unity.Application unityApplication, Hyland.Unity.WorkView.WorkViewExecuteActionButtonScriptEventArgs args)
{
try
{

DialogResult dr = MessageBox.Show(
"Are you sure you want to do this?",
"Action Confirmation",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.ServiceNotification
);

if (dr == DialogResult.Yes)
{
args.AddUIActionMessageBox("You clicked Yes.");
return;
}
else if (dr == DialogResult.No)
{
args.AddUIActionMessageBox("You clicked No.");
return;
}
else
{
args.AddUIActionMessageBox("You did not click Yes or No.");
return;
}

}
catch (Exception ex)
{
unityApplication.Diagnostics.Write(ex.Message);
args.AddUIActionMessageBox("Error Message: " + ex.Message + " \n Source: " + ex.Source + " \n StackTrace: " + ex.StackTrace );
}
}

1 ACCEPTED ANSWER

Scott_McLean
Elite Collaborator
Elite Collaborator

Hi Sam,

Server-side scripts wil not display dialogs on the user workstation. In order to display a MessageBox to the user, the script has to be running client-side. Creating a script as IClientWorkflowScript will allow it to be run from the Unity Client as a client-side execution. I tested this in v15.0.1.84, and it works as expected.

EDIT: After I posted this, I also went back and tested a two-part process with a second prompt relying on the results of the first:

This also works as expected in the Unity Client

Hope that helps.

Kind regards,

Scott

View answer in original post

5 REPLIES 5

Daniel_Quill
Elite Collaborator
Elite Collaborator

Sam,

I would like to second what Scott and Cameron have metioned in their posts.  If the script type chosen is not a client side script type the application server will execute to code.  If the script executes on the application server and a message box is displayed, the server will be unable to handle any required responses.  This will often cause the application server to halt and will require a reset in order to release the process.

Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.