Dynamic Method Call


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

	private void CallDynamicQueryAdapterGetBaqDataViewQueryMethod()
			// 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))

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

			// 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;
			// Call Adapter method
			bool result = adapterDynamicQuery.GetBaqDataViewQuery(pcQueryId);

			// Cleanup Adapter Reference

		} catch (System.Exception ex)


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.

  <localTime>29/01/2021 14:17:12:7655909 PM</localTime>
  <executionTime total="209" roundTrip="188" channel="0" bpm="0" other="21" />
    <parameter name="queryID" type="System.String"><![CDATA[Attachements]]></parameter>

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:

  <localTime>1/29/2021 09:26:11:4519574 AM</localTime>
  <executionTime total="73" roundTrip="56" channel="0" bpm="0" other="17" />
    <parameter name="queryID" type="System.String"><![CDATA[WaferBinSearch]]></parameter>