How do I display a report style based on a certain criteria?

Hello,

I am currently working on configuring a report to display when the beginning of a part matches specific criteria. I have previously implemented a similar functionality using a plant filter, which identifies the plant based on the user’s location. However, when attempting to apply the same method for this new criteria, I encounter four errors upon execution, despite the code compiling successfully.

Below is the code used for the plant customization:

// **************************************************
// Custom code for BAQReportForm
// Created: 20/01/2021 16:40:02
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Ice.BO;
using Ice.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	private EpiDataView edvReportParam;

	string plant;

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **

	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		this.edvReportParam = ((EpiDataView)(this.oTrans.EpiDataViews["ReportParam"]));
		this.edvReportParam.EpiViewNotification += new EpiViewNotification(this.edvReportParam_EpiViewNotification);

		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls
	}

	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		this.edvReportParam.EpiViewNotification -= new EpiViewNotification(this.edvReportParam_EpiViewNotification);
		this.edvReportParam = null;

		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	private void edvReportParam_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
	{
		if ((args.Row > -1))
		{
			if(plant == "HAS")
			{
				view.dataView[0]["ReportStyleNum"] = 1002; // Haslingden
			}
			else
			{
				view.dataView[0]["ReportStyleNum"] = 1; // Dunstable and Hull
			}
		}
	}

	private void BAQReportForm_Load(object sender, EventArgs args)
	{
		if (BAQReportForm.LaunchFormOptions != null)
		{
			string jobNum = BAQReportForm.LaunchFormOptions.ContextValue.ToString();
			edvReportParam.dataView[edvReportParam.Row]["field1"] = jobNum;

			DataTable dtPlant = new DataTable();
        	DynamicQueryAdapter baqAdapter = new DynamicQueryAdapter(oTrans);
        	baqAdapter.BOConnect();

        	QueryExecutionDataSet parameters = new QueryExecutionDataSet();
        	DataRow paramRow;
			paramRow = parameters.ExecutionParameter.NewRow();
        	paramRow["ParameterID"] = "paramJobNum";
       	 paramRow["ParameterValue"] = jobNum;
       	 paramRow["ValueType"] = "string";
        	paramRow["RowMod"] = "A";
        	paramRow["SysRowID"] = new Guid("00000000-0000-0000-0000-000000000000");
        	parameters.ExecutionParameter.Rows.Add(paramRow);

			baqAdapter.ExecuteByID("BAQ_Plant_From_Job", parameters);
		
        	dtPlant = baqAdapter.QueryResults.Tables["Results"];
			plant = dtPlant.Rows[0]["JobHead_Plant"].ToString();
		}
	}
}













Here is the code for the criteria customization:

// **************************************************
// Custom code for PackingSlipPrintForm
// Created: 15/08/2024 09:43:47
// **************************************************

extern alias Erp_Contracts_BO_CustShip;
extern alias Erp_Contracts_BO_ReportQty;


using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Ice.BO;
using Ice.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	private EpiDataView edvReportParam;
	string partNum;

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **

	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		 this.edvReportParam = ((EpiDataView)(this.oTrans.EpiDataViews["ReportParam"]));
 		this.edvReportParam.EpiViewNotification += new EpiViewNotification(this.edvReportParam_EpiViewNotification);

		// End Wizard Added Variable Initialization
		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls
	}

	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		this.edvReportParam.EpiViewNotification -= new EpiViewNotification(this.edvReportParam_EpiViewNotification);
		this.edvReportParam = null;

		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	private void edvReportParam_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
	{
		if ((args.Row > -1))
		{
			if(partNum.StartsWith("PRE003"))
			{
				MessageBox.Show(partNum);
				view.dataView[0]["ReportStyleNum"] = 1007;
			}
		}
	}

	private void PackingSlipPrintForm_Load(object sender, EventArgs args)
	{
		MessageBox.Show("1,2,3"); // error handling
		if (PackingSlipPrintForm.LaunchFormOptions != null)
		{
			MessageBox.Show("3,2,1"); // error handling
			string jobNum = PackingSlipPrintForm.LaunchFormOptions.ContextValue.ToString();
			edvReportParam.dataView[edvReportParam.Row]["field1"] = jobNum;
	
			DataTable dtPartNum = new DataTable(); // create a new datatable based in part number
			DynamicQueryAdapter baqAdapter = new DynamicQueryAdapter(oTrans);
			baqAdapter.BOConnect();
	
			QueryExecutionDataSet parameters = new QueryExecutionDataSet();
			DataRow paramRow;
			paramRow = parameters.ExecutionParameter.NewRow();
			paramRow["ParameterID"] = "paramPartNum";
			paramRow["ParameterValue"] = jobNum;
			paramRow["ValueType"] = "string";
			paramRow["RowMod"] = "A";
			paramRow["SysRowID"] = new Guid("00000000-0000-0000-0000-000000000000");
			parameters.ExecutionParameter.Rows.Add(paramRow);
	
			baqAdapter.ExecuteByID("BAQ_PFP", parameters);
			
			dtPartNum = baqAdapter.QueryResults.Tables["Results"];
			partNum = dtPartNum.Rows[0]["ShipDtl_PartNum"].ToString();
			MessageBox.Show(dtPartNum.Rows[0]["ShipDtl_PartNum"].ToString());
		}
	}




}

I would greatly appreciate it if anyone familiar with this issue could provide a solution or offer assistance.

Thank you in advance for your help.

Welcome! What errors did you get?

1 Like

These are the errors

EPIC ERRORS
---------------------------------------
Exception caught in: Rpt.PackingSlipPrint.PackingSlipPrintForm.EP.28939.Customization.15_08_2024_TM.CustomCode

Error Detail 
============
Message: Object reference not set to an instance of an object.
Program: Rpt.PackingSlipPrint.PackingSlipPrintForm.EP.28939.Customization.15_08_2024_TM.CustomCode.dll
Method: edvReportParam_EpiViewNotification

Client Stack Trace 
==================
   at Script.edvReportParam_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
   at Ice.Lib.Framework.EpiViewNotification.Invoke(EpiDataView view, EpiNotifyArgs args)
   at Ice.Lib.Framework.EpiDataView.OnEpiViewNotification(EpiNotifyArgs e)
   at Ice.Lib.Framework.EpiDataView.InnerNotify(EpiNotifyArgs args)
   at Ice.Lib.Framework.EpiTransaction.NotifyAll()
   at Ice.Lib.Framework.EpiBaseForm.setupUIElements()
---------------------------------------
Application Error
Exception caught in: Rpt.PackingSlipPrint.PackingSlipPrintForm.EP.28939.Customization.15_08_2024_TM.CustomCode

Error Detail 
============
Message: Object reference not set to an instance of an object.
Program: Rpt.PackingSlipPrint.PackingSlipPrintForm.EP.28939.Customization.15_08_2024_TM.CustomCode.dll
Method: edvReportParam_EpiViewNotification

Client Stack Trace 
==================
   at Script.edvReportParam_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
   at Ice.Lib.Framework.EpiViewNotification.Invoke(EpiDataView view, EpiNotifyArgs args)
   at Ice.Lib.Framework.EpiDataView.OnEpiViewNotification(EpiNotifyArgs e)
   at Ice.Lib.Framework.EpiDataView.InnerNotify(EpiNotifyArgs args)
   at Ice.Lib.Framework.EpiTransaction.NotifyAll()
   at Ice.Lib.Framework.EpiTransaction.NotifyAll(NotifyType type, EpiDataView view)
   at Erp.UI.Rpt.PackingSlipPrint.Transaction.setPackNum(String PackNum)
   at Erp.UI.Rpt.PackingSlipPrint.PackingSlipPrintForm.OnFormLoaded()
   at Ice.Lib.Framework.EpiBaseForm.InnerFormLoaded()
-------------------------------------------
Application Error
Exception caught in: mscorlib

Error Detail 
============
Message: Exception has been thrown by the target of an invocation.
Inner Exception Message: Object reference not set to an instance of an object.
Program: CommonLanguageRuntimeLibrary
Method: InvokeMethod

Client Stack Trace 
==================
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Ice.Lib.Customization.CustomScriptMethodInvoker.InvokeScriptMethod(MethodInfo scriptMethod, Object[] parameters)
   at Ice.Lib.Customization.CustomScriptMethodInvoker.InvokeCustomFormLoadIfExists(String methodName, Object sender, EventArgs e)
   at Ice.Lib.Customization.CustomScriptManager.<>c__DisplayClass104_0.<OnCustomCodeFormLoad>b__0()
   at Ice.Lib.Customization.CustomScriptManager.TryActionShowExceptionBoxOrLogVerificationErrorIfException(Action action, String exceptionBoxTitle)
Inner Exception 
===============
Object reference not set to an instance of an object.



   at Script.PackingSlipPrintForm_Load(Object sender, EventArgs args)

-------------------------------------------
Application Error
Exception caught in: Rpt.PackingSlipPrint.PackingSlipPrintForm.EP.28939.Customization.15_08_2024_TM.CustomCode

Error Detail 
============
Message: Object reference not set to an instance of an object.
Program: Rpt.PackingSlipPrint.PackingSlipPrintForm.EP.28939.Customization.15_08_2024_TM.CustomCode.dll
Method: edvReportParam_EpiViewNotification

Client Stack Trace 
==================
   at Script.edvReportParam_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
   at Ice.Lib.Framework.EpiViewNotification.Invoke(EpiDataView view, EpiNotifyArgs args)
   at Ice.Lib.Framework.EpiDataView.OnEpiViewNotification(EpiNotifyArgs e)
   at Ice.Lib.Framework.EpiDataView.InnerNotify(EpiNotifyArgs args)
   at Ice.Lib.Framework.EpiReportTransaction.RefreshPrams()
   at Ice.Lib.Report.EpiReportFunctions.ModifyReportToolbar(UltraToolbarsManager baseToolbarsManager, EpiReportTransaction trans)
--------------------------------------------
1 Like

Do you see any of your message boxes? Or do these errors happen once you open the form?

these are 4 message boxes which display the error it starts at error detail. Where i have error handling highlighted it displays them message boxes. I do think it has something to do with

		 this.edvReportParam = ((EpiDataView)(this.oTrans.EpiDataViews["ReportParam"]));
 		this.edvReportParam.EpiViewNotification += new EpiViewNotification(this.edvReportParam_EpiViewNotification);

And I have seen something called report style wizard adapter in the wizard but I’m not sure on how to implement that or if it is relevant (it does but I didn’t need it when I created the plant criteria) .

I’m not sure what your use case is, but it seems like this might be a use for Advanced Print Routing.

1 Like

The goal of this is to automatically select report style 1007 if the part number contains PRE003 at the start.

I agree w/ @danvoss.

You could set up and test an APR like below:

If the Condition is “True” then you use the Alternate Report Style and set it to your 1007.
image

If “False” it would print the default style.

No code to trouble-shoot… so, may be worth testing.

4 Likes

Hello dcamlin,

This looks way more straightforward, however do I do this on the default report style or 1007?

The default.

It’ll print your special style when the criteria is met.

2 Likes

Thank you so much! I will be using this method in the future.