Force User to Enter Value in BAQ Report Option Field

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?

Can you go to the underlying BAQ, and put a Table Criteria on the JobHead table - ensuring that the JobNum > 0.

This can be done with a customization on the Report Screen. I’ll find the code.

1 Like

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;
	}

}
2 Likes

This code is in high demand @hkeric.wci

1 Like

If you don’t want to do a customizatiopn or code, set a default on the BAQ Report Designer

If they don’t change that default they’ll get nothing.

It’s not nearly as nice as disabling the print button until the field is entered, but its a quick and dirty solution.

This is great thankyou but I cant get it to compile

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);
			}
		}

Thankyou - getting compile error:

EDIT

Here’s the whole function which seems to work
(looks like I left out a break; or two when I was tidying it up)

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 = "35035f26-2e63-4218-9d88-c992289dfd89-1";
				//whereClause = this.buildBatchesWhereClause();
				EpiTextBox option1 = (EpiTextBox)csm.GetNativeControlReference("e3bb1f42-0b31-4ee1-abd0-8790da93822d");
				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);
					break;
					}
				break;
		}
	}

thanks that compiles, however its still not popping up with the message box …

I used my filter grid guid, and removed the option1 as I only need to check for whats in the grid…

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()

Either manually add those two highlighted lines, or use the Form Event Wiz to add them and the empty function for BAQReportForm_BeforeToolClick

EDIT

I was only testing it with PrintPreview, and had closed SysMonitor :man_facepalming:
The warning did show, but still printed

The sample code doesn’t include anything to stop it from printing. I’ll look for that.

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)

image

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"

1 Like

Hi

Thanks ever so much, after adding the Handled line it magically started working!!!

image

It looks like you have Client and Server printing enabled, so you shouldn’t need the "PrintTool" case added.