I have set up a custom button in the Content Editor that makes a third-party API call when clicked. In order to let the user know that the client is performing some work, I have implemented a ProgressBox. I would also like to alert the user at the end to any errors that may have occurred (it's not enough to tell them to check to the logs). Here is how my code is set up.
public override void Execute(CommandContext context)
{
string message = "Result\r\n";
Sitecore.Shell.Applications.Dialogs.ProgressBoxes.ProgressBox.Execute(
"Push To API",
"API Call",
new Sitecore.Shell.Applications.Dialogs.ProgressBoxes.ProgressBoxMethod(StartProcess),
new object[] { });
SheerResponse.Alert(message);
}
public void StartProcess(params object[] parameters)
{
// API call (or calls) happen here. After the API calls are finished
// the message value gets set to reflect what happened during the
// process
}
My goal is to trigger the Alert Box after the StartProcess has fully completed.
However, the Execute method runs asynchronously, so the Alert Box always runs with a message of "Result ".
Another thing to note is that I've been adding progress messages to the Progress box using code like this inside the StartProcess method.
Sitecore.Context.Job.Status.Messages.Add($"There has been an error with {item.Name}");
This is not sufficient for my needs, because the ProgressBox closes immediately upon creation of the process. Thanks in advance for any assistance here.