I have a BAQ report where a user enters a Job Number that then prints the Part Number and a UD Field to a label printer through Advanced Print Routing.
The problem is sometimes they are clicking Generate Only with the Job Number field blank. This is generating a BAQ Report Result set in my reporting database that is over 1 million records. Luckily it isn’t sending this to the label printer, but the report table is getting stuck in my report database and not purging as it should be (that’s a different problem with my reporting database size that I’m working on with support).
I’m looking for a way to stop the report from being submitted and give the user an error message stating that the Job Number field is blank. Is there a way I can accomplish this?
Probably just a BeforeToolClick? Add the Generate Tool as a case.
private void BAQReportForm_BeforeToolClick(object sender, Ice.Lib.Framework.BeforeToolClickEventArgs args)
{
switch (args.Tool.Key)
{
case "PrintClientTool":
case "PrintServerTool":
case "PrintPreviewTool":
// Build whereClause so we can inspect it
string whereClause = this.buildBatchesWhereClause();
if (whereClause == string.Empty)
{
args.Handled = true;
EpiMessageBox.Show("You Must Select Filters, Unable to Print Wide Open.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (args.Tool.Key != "PrintPreviewTool" && this.IsWatermarkEnabled())
{
args.Handled = true;
EpiMessageBox.Show("When Watermark is Enabled you can only Print Preview.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
break;
}
}
Instead of building a WhereClause from the options and filters, you can add code to detect if the Filter grid is empty, like:
switch (args.Tool.Key){
case "PrintClientTool":
case "PrintServerTool":
case "PrintPreviewTool":
// added an option var for each option field
EpiTextBox option1 = (EpiTextBox)csm.GetNativeControlReference("e3bb1f42-0b31-4ee1-abd0-8790da93822d");
// added an filter var for each filter grid
EpiUltraGrid filterGrid = (EpiUltraGrid)csm.GetNativeControlReference("35035f26-2e63-4218-9d88-c992289dfd89-1");
if(filterGrid.Rows.Count == 0 && option1.Text == ""){
EpiMessageBox.Show("You Must Select Filters or enter option field, Unable to Print Wide Open.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Are you testing it from a menu item? If so, have you selected the Customization for that menu item, and Logged out and back in again (I’ve had changes to the menus not take effect until after exiting and relaunching).
Test it in the BAQ Report Designer.
Did you use the Form Event Wizard to create the function, or did you just copy and paste it into the Script editor?
The later (just pasting the function) doesn’t create the necessary calls in public void InitializeCustomCode() and public void DestroyCustomCode()
Add args.Handled = true; as shown below. This will trick the button click into thinking it was handled, thus not causing it to submit the task. After clearing the message box, the status bar still says Ready (like you never clicked a button)
EDIT
One more thing… Depending on the Company Config (allow client and/or server printing), you may have to add a case for "PrintTool" too.
Other cases you might want to include are "EmailTool" and "GenerateTool"