Today I want to share with you some practices how you can do iteration with user from Acumatica business logic code. In general:
- You can ask some simple question with strait forward answer, like: “Do you really want to delete this record? Yes/No”
- You can use redirection feature to redirect user to some hidden screen, where he will do some additional configuration and processing.You can hide screen by putting it into the hiden folder of Acumatica sitemap. When screen is hidden user can access it only with redirection from some other screen.
- But if you want to do more interactive dialog with user you may need use popup dialog with smart panel. In This case you can show some configuration to user that is related to requested operation. This panel will be hidden on the screen until you call it with appropriate code from your business logic. When user close panel, your code will be automatically notified about configuration changes.
The first and simplest way to communicate with user is just simple dialog.
Please note some important notes about dialogs:
- When you call “Ask” method from DataView, system will throw PXDialogRequiredException. You should not catch it as it is good exception, that will be automatically handled by user presentation logic. When user will answer on the question, system will automatically rund your method in second time. In this case DataView will have dialog result from user interface, so exception will not be thrown. So you need to plan your business logic according to the rule, that your code will be called twice.
- You need to aware about localization of your questions by you own. In general your message should be a constant string in some static class with [PXLocalizableAttribute]. When you are colling dialog, you should call localization engine manually by function: PXMessages.LocalizeFormatNoPrefix(…);
Smart panels are similar to web dialogs, but instead of showing simple question, system will show a specific control – smart panel, that will be mapped to some DataView inside business logic container. Smart panel should have at least one container control (PXForm, PXGrid, PXTab), that will be mapped to the same DataView as smart panel. Container control will select and update data inside PXCache that is associated with their DataView.
Business logic code snippet:
Presentation logic code snippet (*.aspx):
Some points from these examples:
- Panel is mapped to DataView by attribute “Key”
- To call smart panel you need to use “AskExt” method instead of using standard “Ask”
- If you need buttons, you need to define it by your own in the smart panel:
- Use panel with predefined skin – SkinID=”Buttons”.
- Specify dialog result for all buttons – DialogResult=”OK”.
- Enable auto-callback if you need to commit cahnges from smart panel of OK button – <AutoCallBack Command=”Save” Target=”frmMyCommand” />.
Now it should works fine. Have a nice development!