How can I add success and failure notifications?

Generally it’s a pretty nice thing to let your users know that the transaction they just entered was successful. This article shows how you can add simple success and failure notifications.

Toasts are a great way of doing that, they are unobtrusive, automatically dismiss themselves, and don’t interfere with the user interacting with the app. In this case, I am doing a location transfer, and I want to let the user know that it was successful:

1_sdwx-gvI711mKVv5u8X5iw

In this case, when the user scans the quantity, an ‘On Demand’ data subscription called CommitTransfer is called. This is a dynamic plugin I wrote using C# on the Bezlio Remote Data Broker server located in the Dynamic folder of my installation directory.

datasub

It is important to mark it as an ‘On Demand’ data subscription so that it does not try and run the data subscription when the bezl is first launched. The code to tell Bezlio to process the data subscription is:

bezl.dataService.process('CommitTransfer');

 

Now I need to check the results of the data subscription and if it is successful, show our notification. I do this in onDataChange:

switch(bezl.data.changed) {
case 'CommitTransfer':
if (bezl.data.CommitTransfer == 'Success' ) {
bezl.notificationService.showSuccess('Location Transfer Successful!');
} else {
bezl.notificationService.showError(bezl.data.CommitTransfer);
}
break;
}

 

I am switching on bezl.data.changed because onDataChange is called every time a data subscription is returned. I can use bezl.data.changed to know what data subscription is being returned, and I only want this code to call when CommitTransfer returns. My Dynamic plugin returns success if successful and throws an error otherwise. I can use bezl.notificationService.showSuccess to show a success message or showError if there is an error.