WHMS validations: where can I put my code

 


Ever come across a situation where you needed to induce validations, in Warehouse Management mobile apps, before letting the user finally submit data? 
For example: you need to check if the supplied value for the target license plate, while shipping a transfer order, must be exactly 12 characters long. Or the supplied date of a warehouse Load must be more than or equal to 5 days from today. Or imagine there is a flag in your warehouse, called Stopped for all transactions and while doing GRN from your mobile app, you need to see if it's a stopped warehouse.
For all such situations, there is a trusted class (dedicated exclusively for WHMS) called: WhsControl and you need to wisely put your code there.
Essentially WhsControl is a class that has all the variables stacked up in it: the associated WMSLocationId, InventLocationId or ItemId or even the calling menu item. You can simply do a CoC on "processControlUsingDisplay" method, so as to perform these validations and return true or false accordingly.
The below example shows how to check if your license plate is 12 characters long:
#WHSRF
#WHSWorkExecuteControlElements
#WHSWorkExecuteDisplayCases

#define.callingMenuTransferOrder("ShipTransferOrder")
protected boolean processControlUsingDisplay(str _value)
{
    boolean ret = next processControlUsingDisplay(_value);
    if (this.parmName() == #TargetLicensePlateId && 
         _value &&
        this.parmMenuItemName() == #callingMenuTransferOrder)
    {
        if (!this.validateCharacterCount(_value))
        {
            this.fail(/*Label file for invalid character count*/);
        }
    }
    return ret;
}

The method validateCharacterCount checks the logic for the 12-character long code of the target license plate.
Here the referred macros: WHSRF contains the definitions for TargetLicensePlate, MenuItems, etc. and you can ask the code only to be triggered when called from ShipTransferOrder menu.
(I mentioned, wisely, in my above statement ☝☝☝ : for example, the above code only checks if this is called from TransferOrder shipment -- certainly this should not get called from everywhere).
Lastly see the method: this.fail(): this method carries the result of the validation and is equivalent of 'Ret = checkFailed()' [in fact its sets ret = checkFailed, internally].

Comments

Popular posts from this blog

X++ : mistakes which developers commit the most

Make your menu items visible on main menu, conditionally,, using this cool feature of D365FO

Speed up your execution performance by using SysGlobalCaches