Dynamic Method Call

Hi,

I have had a lot of help from this forum before but I am reaching out again as I can’t figure out what is going on with my code.
I have put a Dynamic method call in my customisation which I want to fire from a button click however it runs when I open the dashboard. I have done this a few times before and I can’t see the difference in the script, any help would be greatly appreciated.


// **************************************************
// Custom code for MainController
// Created: 27/01/2021 16:27:56
// **************************************************
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;
using Ice.Bpm.Context;

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

	// 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

		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		this.epiButtonC1.Click += new System.EventHandler(this.epiButtonC1_Click);
		// 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.epiButtonC1.Click -= new System.EventHandler(this.epiButtonC1_Click);
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	private void epiButtonC1_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		CallDynamicQueryAdapterGetBaqDataViewQueryMethod();
	}

	private void CallDynamicQueryAdapterGetBaqDataViewQueryMethod()
	{
	try
		{
			// Declare and Initialize EpiDataView Variables
			EpiDataView edvV_Attachements_1View = ((EpiDataView)(this.oTrans.EpiDataViews["V_Attachements_1View"]));

			// Check if valid EpiDataView Row(s) are selected
			if ((edvV_Attachements_1View.Row < 0))
			{
				return;
			}

			// Declare and create an instance of the Adapter.
			DynamicQueryAdapter adapterDynamicQuery = new DynamicQueryAdapter(this.oTrans);
			adapterDynamicQuery.BOConnect();

			// Declare and Initialize Variables
			// TODO: You may need to replace the default initialization with valid values as required for the BL method call.
			string pcQueryId = ((string)(edvV_Attachements_1View.dataView[edvV_Attachements_1View.Row]["Attachements"]));
			{
			adapterDynamicQuery.BpmContext = new ContextDataSet();
			var row = adapterDynamicQuery.BpmContext.BpmData.NewRow();
			row["Number01"] = ((edvV_Attachements_1View.dataView[edvV_Attachements_1View.Row]["XFileRef_XFileRefNum"]));
			row["SysRowID"] = Guid.Empty;
			adapterDynamicQuery.BpmContext.BpmData.Rows.Add(row);
			}
			// Call Adapter method
			bool result = adapterDynamicQuery.GetBaqDataViewQuery(pcQueryId);

			// Cleanup Adapter Reference
			adapterDynamicQuery.Dispose();

		} catch (System.Exception ex)
		{
			ExceptionBox.Show(ex);
		}
	}
}

Allan

How are you verifying it runs on Load?

I have a BPM that listens for the queryId which would open a data form when you click the button but it opens on load.
The trace log confirms it.

<tracePacket>
  <businessObject>Ice.Proxy.BO.DynamicQueryImpl</businessObject>
  <methodName>GetByID</methodName>
  <appServerUri>net.tcp://novo-svr-ep01/EpicorERP/</appServerUri>
  <returnType>Ice.Tablesets.DynamicQueryTableset</returnType>
  <localTime>29/01/2021 14:17:12:7655909 PM</localTime>
  <threadID>1</threadID>
  <correlationId>e3273a2b-0eaa-4de8-872a-f3ade147b80d</correlationId>
  <executionTime total="209" roundTrip="188" channel="0" bpm="0" other="21" />
  <retries>0</retries>
  <parameters>
    <parameter name="queryID" type="System.String"><![CDATA[Attachements]]></parameter>
  </parameters>
</tracePacket>

I would expect to see DynamicQuery.GetByID in the trace on load, triggered by core logic. The query ID would be the name of the query behind the dash.

I just tested a dahsboard which has no customization on it and I see that in the trace:

<tracePacket>
  <businessObject>Ice.Proxy.BO.DynamicQueryImpl</businessObject>
  <methodName>GetByID</methodName>
  <appServerUri>net.tcp://XXXXXXX/ERP10Test/</appServerUri>
  <returnType>Ice.Tablesets.DynamicQueryTableset</returnType>
  <localTime>1/29/2021 09:26:11:4519574 AM</localTime>
  <threadID>1</threadID>
  <executionTime total="73" roundTrip="56" channel="0" bpm="0" other="17" />
  <retries>0</retries>
  <parameters>
    <parameter name="queryID" type="System.String"><![CDATA[WaferBinSearch]]></parameter>
  </parameters>