Barcode Scan Commands: To Implement a Custom Command
This activity will walk you through the process of defining a custom command for a scan mode.
Story
Suppose that you are creating a custom scan mode for a barcode-driven form. You have
defined the list of commands for this scan mode and introduced the
ConfirmCommand
command in this scan mode. You now need to
implement the custom ConfirmCommand
command.
Process Overview
You will specify the required properties of the ConfirmCommand
scan
command, which is a new custom command, and implement its
Process() method.
System Preparation
Before you begin performing the step of this activity, do the following:
- Prepare an MYOB Acumatica instance by performing the Test Instance: To Deploy an Instance prerequisite activity.
- Create a barcode scan class by performing the Barcode Scan Class: To Create a Barcode Scan Class prerequisite activity.
- Create the scan mode and define its required properties by performing the Barcode Scan Mode: To Define the Required Properties prerequisite activity.
- Define the list of commands for the scan mode by performing the Barcode Scan Commands: To Define the List of Commands prerequisite activity.
Step: Defining the Custom Command
To implement the
ConfirmCommand
, do the following:- In the
CountMode
class, add theConfirmCommand
class for the custom command and define its required properties, as shown in the following code.public class INScanCount : WMSBase { public sealed class CountMode : ScanMode { ... public sealed class ConfirmCommand : ScanCommand { public override string Code => "CONFIRM"; public override string ButtonName => "scanConfirmDocument"; public override string DisplayName => Msg.DisplayName; protected override bool IsEnabled => Basis.DocumentIsEditable; [PXLocalizable] public abstract class Msg { public const string DisplayName = "Confirm"; } } ... } }
- In the
RefNbrState.Msg
class, add the following message.public const string NotSet = "The document number is not selected.";
- In the
CountMode
class, add the Process() method implementation, as shown in the following code.public class INScanCount : WMSBase { public sealed class CountMode : ScanMode { ... public sealed class ConfirmCommand : ScanCommand { ... protected override bool Process() { if (Basis.Document == null) Basis.ReportError(RefNbrState.Msg.NotSet); if (Basis.DocumentIsEditable == false) Basis.ReportError(RefNbrState.Msg.InvalidStatus, Basis.DocumentView.Cache.GetStateExt<INPIHeader.status>( Basis.Document)); BqlCommand nullPhysicalQtyCmd = BqlCommand.CreateInstance( Basis.Details.View.BqlSelect.GetType()); nullPhysicalQtyCmd = nullPhysicalQtyCmd.WhereAnd<Where< INPIDetail.physicalQty.IsNull>>(); PXView nullPhysicalQtyView = Basis.Graph.TypedViews.GetView( nullPhysicalQtyCmd, false); foreach (INPIDetail detail in nullPhysicalQtyView.SelectMulti(). RowCast<INPIDetail>()) { Basis.Details.SetValueExt<INPIDetail.physicalQty>(detail, 0m); Basis.Details.Update(detail); } Basis.SaveChanges(); Basis.DocumentView.Current = null; Basis.CurrentMode.Reset(fullReset: true); Basis.ReportInfo(Msg.CountConfirmed); return true; } [PXLocalizable] public abstract class Msg { ... public const string CountConfirmed = "The count has been saved."; } } ... } }