06.11.2019, 13:11 | #1 |
Участник
|
erconsult: Input validation and messaging in the Process Guide Framework
Источник: http://erconsult.eu/blog/validation-process-guide/
============== A few words of introduction: Process Guide framework is THE framework for new Warehouse management mobile screens and menu items in “Dynamics 365 Supply Chain Management”: …/warehousing/process-guide-framework I find that the topic of the validation of data entered or scanned by the user is very superficially covered. If you read the above shallow documentation you may think that the way to give an error on a wrong entry is the ProcessGuideStep.isComplete() method, but it is NOT a good place. It would be too late: by the time the execution reaches isComplete() the user input has already been processed, accepted and serialized in the session state aka “pass” WHSRFPassthrough. I figured out that the true validation may be programmed at 2 places: in the process() method of a class derived from the WHSControl or in the ProcessGuideStep.validateControls() method. The 2 ways require slightly different techniques and have distinct flavours: WHSControl.process() Inheriting the WHSControl class offers an object-oriented alternative to extending the WHSRFControlData class (this spaghetti code has been recently refactored and moved to WHSRFControlData.processLegacyControl). This technique is briefly described in the blog …/mfp/posts/extending-whs-adding-a-new-control-type . There are pros and cons. The class is going to be used across the whole warehouse mobile app whenever you add a control with this name. This can be both good and bad:
#WHSRF [WhsControlFactory(#ProdIdLabel)] public class WHSControlProdId extends WhsControl { public boolean process() { boolean ok = super(); ProdId prodId = this.parmData(); fieldValues.insert(ProcessGuideDataTypeNames::ProdId, prodId); if (! ProdTable::exist(prodId)) { ok this.fail("@WAX1162"); // The production or batch order number is not valid } return ok; } } Note that you have to care about parsing the entry and storing it in the fieldValues container. On a error, the processing stops, the page reloads and the error message(s) is shown: ProcessGuideStep.validateControls() The validation in the ProcessGuideStep class has a different quality:
[ProcessGuideStepName(classStr(ProcessGuideItemConsumpPromptQtyStep))] class ProcessGuideItemConsumpPromptQtyStep extends ProcessGuideItemStep { protected void validateControls() { WhsrfPassthrough pass = controller.parmSessionState().parmPass(); super(); qty = processingResult.fieldValues.lookup(ProcessGuideDataTypeNames::Qty); if (qty * pass.parmQty() < 0) { throw warning("@SYS25506"); // Quantity may not change sign } } protected ProcessGuidePageBuilderName pageBuilderName() { return classStr(ProcessGuideItemConsumpPromptQtyPageBuilder); }} The warning thrown interrupts the flow, re-loads the page and presents the warning. Success message A related topic is an ability to present a success message to the user at the end of the process execution. You do it at the end of the doExecute() method in the process guide step: protected void doExecute() { super(); // do the work this.addProcessCompletionMessage(); } This implementation is very limited, however: it cannot uptake a custom message and always shows the same text “Work Completed”. The below snippet is smarter: ProcessGuideMessageData messageData = ProcessGuideMessageData::construct(); messageData.message = strFmt("@SYS24802", journalId); // Journal cannot be posted because it contains errors. messageData.level = WHSRFColorText::Warning; navigationParametersFrom = navigationParametersFrom ? navigationParametersFrom : ProcessGuideNavigationParameters::construct(); navigationParametersFrom.messageData = messageData; Unrelated conclusion: use the process guide framework and say goodbye to the WHSWorkExecute mess! The post Input validation and messaging in the Process Guide Framework appeared first on ER-Consult. Источник: http://erconsult.eu/blog/validation-process-guide/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|