LaunchFormOptions Basic Steps

I am attempting to put a button on the DMR processing screen that pulls up our DMR Form with the DMR number populated from the DMR processing screen. So far I have been able to get the button to open the form, but not pass any info.

Code that works to open BAQ Report form:

ProcessCaller.LaunchForm (oTrans, “UDDMR”);

What I think I need to have to pass information:

LaunchFormOptions lfo = new LaunchFormOptions ();
lfo.IsModal = true;
lfo.ValueIn = ?????????;
ProcessCaller.LaunchForm (oTrans, "UDDMR", lfo);

What do I put in ??? I want the DMR number, I have tried DMRHead.DMRNum (what the field is tied to), I have also tried nedDMRNum (the epiview name?).

I have read a ton of posts but can’t seem to figure out how to reference the field I want.

My next question is about the receiving form. I have to customize it to receive the ValueIn? Do I do this on the screen that pops up for me to print the form from (where I enter the DMR number and choose the report format)?

1 Like

LFO Basics

In ValueIn you can pass in whatever you like, for example.

Form 1 Button Code:

LaunchFormOptions lfo = new LaunchFormOptions();
lfo.IsModal = true; // true will basically not allow the user to do anything on Form1 until Form2 is closed.
lfo.ValueIn = "Hey Mark Wonsil, Got Anymore Dad Jokes?";
ProcessCaller.LaunchForm(oTrans, "UDDMR", lfo);

I mean anything…

lfo.ValueIn = this.oTrans; // lets just passed all of oTrans - not recommended but yeah you could
lfo.ValueIn = 123;
lfo.ValueIn = new List<int>() { 2, 3, 7 };

Then on the Form you are calling, you can capture the lfo object and read the value, then you do with it whatever you wish on the other side.

Form 2 Example (The Form you are Launching):
I did mine on the _Shown Event because I wanted to seperate my _Load code and dedicate an event of its own.

private void UD100Form_Shown(object sender, EventArgs e)
{
	// Check for Called
	if (UD100Form.LaunchFormOptions != null && UD100Form.LaunchFormOptions.Sender != null && UD100Form.LaunchFormOptions.ValueIn != null)
	{

		string lfoValue = UD100Form.LaunchFormOptions.ValueIn.ToString();
		string lfoSenderName = UD100Form.LaunchFormOptions.Sender.ToString();

		switch (lfoSenderName)
		{
			case "Erp.UI.Rpt.PackingSlipPrint.Transaction":
				DataSet dsShipDtl = ShipDtlSearchAdapter(lfoValue);

				foreach (DataRow ShipDtlRow in dsShipDtl.Tables[0].Rows)
				{
					jobNum = ShipDtlRow["JobNum"].ToString();
					AutoCreateRecordsByJobNum(jobNum);
				}

				break;

			case "Erp.UI.App.JobEntry.Transaction":
				jobNum = lfoValue;
				AutoCreateRecordsByJobNum(jobNum);
				break;
		}
	}
}

To Simplify all you really need on the other side to get started it:

	if (UD100Form.LaunchFormOptions != null && UD100Form.LaunchFormOptions.Sender != null && UD100Form.LaunchFormOptions.ValueIn != null)
	{
		string lfoValue = UD100Form.LaunchFormOptions.ValueIn.ToString();
       EpiMessageBox.Show("The Value Passed in is " + lfoValueIn, "Hi", MessageBoxButtons.OK, MessageBoxIcon.Error);
	}

Extra Credit 1 - Communicate Closed Event

You can also communicate between the 2 forms and even detect the closing of the Form Called.

Form 1:

private void btnTest_Click(object sender, System.EventArgs args)
{
	LaunchFormOptions lfo 	= new LaunchFormOptions();
	lfo.ValueIn				= this.oTrans._packNum;
	//lfo.ContextValue		= this.CreateParamsList(whereClauseUD100A);
	lfo.IsModal				= true;
	lfo.SuppressFormSearch 	= true;
	lfo.LaunchedFormClosed += new EventHandler(lfo_LaunchedFormClosed);
	//lfo.CallBackMethod = CallBackHandlerBAQReport;
	ProcessCaller.LaunchForm(oTrans, "UEVQRT01", lfo);
}

void lfo_LaunchedFormClosed(object sender, EventArgs e)
{
	if (((EpiBaseForm)sender).DialogResult == System.Windows.Forms.DialogResult.OK)
	{
		// Do MAGIC Here the sender or e object will have the called form data and LFO Object Result, it literally will send over the entire Object, oTrans info etc... 
	}
}

Form 2:

UD100Form.DialogResult = DialogResult.OK;
UD100Form.LaunchFormOptions.Result = "HELLO WORLD";

I actually use this when I have a BAQ Form and I want to “Auto-Print” I Launch it, hidden or even visible and then return result and close it.


Extra Credit 2 - Call Back Methods

You can also register a CallBack Method, so Form2 can actually call a Method on Form1. This is one trick I learned from @josecgomez

lfo.CallBackMethod = CallBackHandlerBAQReport;

Form 1:

/**
* Helper which listens to Communication from the BAQ Report
* Invoke from the BAQ Report for example to Refresh UI
* After Printing has happened so the Shape shows up
*/
void CallBackHandlerBAQReport(object sender, object CallBackArgs)
{
	// Verify CallBack args exist
	if (CallBackArgs == null) {
		return;
	}

	// We are passing back a string
	switch (CallBackArgs.ToString())
	{
		case "Refresh":
			this.oTrans.Refresh();
			break;
	}
}

Form 2: (One being Launched):

if (BAQReportForm.LaunchFormOptions != null)
{
	if (BAQReportForm.LaunchFormOptions.CallBackMethod != null) {
		BAQReportForm.LaunchFormOptions.CallBackMethod(oTrans, "Refresh");
	}
}

Basically you can pass back anything as well

BAQReportForm.LaunchFormOptions.CallBackMethod(oTrans, "ANYTHING_I_WISH_HERE");

My Use Case for this is when I Update my Form1 Data using its Adapter on Form2 and then I send a refresh to the background form and it updates. But you can actually do that with the previous discussed method Extra Credit 1 - Communicate Closed Event as well.

The same methods are used for example when you Print a Packing Slip and then the Customer Shipment Form updates with the green shape “Printed” or shows a Message Box…

20 Likes

Great post @hkeric.wci, @josecgomez Any chance we can have this one put in Experts Corner?

1 Like

Wow! That is a wonderful explanation. Unfortunately it goes right over my head. I still don’t understand how to reference the field I’m looking at (DMR number) in the code. All the example have words in quotes. Do I just put “DMRnumber” right there and it will pick the one I’m looking at?

Then on the Form you are calling, you can capture the lfo object and read the value, then you do with it whatever you wish on the other side.

Do I do this by choosing Customize on the screen that pops up to print my report?

Completely new at this :slight_smile:
Thanks
Melissa

I think you are asking how to get the DMRNum value?

First declare a variable to reference the header.

private EpiDataView _edvDMRHead;

then initialize it in the InitializeCustomCode() procedure;

Or you could string it all together in a long statement, but I like to split stuff out :slight_smile:

this.edvDMRHead = ((EpiDataView)(this.oTrans.EpiDataViews[“DMRHead”]));

When you want to reference the DMRNum, you’ll look at

ValueIn = (int)_edvDMRHead[“DMRNum”];

1 Like

So what if the called form (Form 2) was not modal and you wanted to make it behave like as is you had performed an Open With from the Calling form.

Example, calling the picking list from a button the sales order, you pass in the ordernum as a parameter for pick list print, but instead of closing the print dialog, you click back on the SO form and either enter in another SO number or select one from the navigator, changing the SO header and its details how would you reflect that SO number change as a parameter in the picking list print filter tab?

Hi,

It is posible launch a form with spescific customization?

Yea create a menu (process) and launch that

A process is a menu that is not visible in the tree

1 Like

Hi, it works perfectly, thanks.

I’m actually trying to nail this down myself. I want to be able to launch a BAQ Report from right-click context menu. I’ve got the context menu item created and I can pass the order number to the BAQ Report and it reads it into the report option field. It will then print preview automatically. At this point, if nothing else, I have saved a few mouse clicks. The only thing left is: how can I close the report print screen?

Any advice?

Update. I’ve gotten it to print and close the form… but I keep getting this error. Any ideas?

private void BAQReportForm_Load(object sender, EventArgs args)
	{
		// Check to see if this report was called with an Order Number available. If so we will print preview automatically.
		if(BAQReportForm.LaunchFormOptions != null)
		{
			int orderNum;
			string val = BAQReportForm.LaunchFormOptions.ValueIn.ToString();
			
			if (val.Contains("~"))
			{
				string[] items = val.Split('~');
				orderNum = Convert.ToInt32(items[0]);
			}
			else
			{
				orderNum = Convert.ToInt32(val);
			}

			EpiDataView view = ((EpiDataView)(this.oTrans.EpiDataViews["ReportParam"]));

			view.dataView[view.Row].BeginEdit();
			view.dataView[view.Row]["field1"]= orderNum;
			view.dataView[view.Row].EndEdit();

			this.oTrans.RunDirect("Preview");

			EpiBaseForm thisForm = (EpiBaseForm)(csm.GetNativeControlReference("2dcd1674-5e34-4d98-b493-c75747027376"));
			thisForm.Close();
		}	

image
image

I feel like it has something to do with the objects not getting created/disposed before you are closing the form.

So you wouldn’t want to run the form.Close on form_Load, but rather do it on Loaded or something like that.

1 Like

image
Which would you think would be best?

I usually use _Shown its not in the Wizard list, you must simply add it yourself via code.

// InitializeCustomCode
this.UD100Form.Shown += UD100Form_Shown;

// DestroyCustomCode
this.UD100Form.Shown -= UD100Form_Shown;

private void UD100Form_Shown(object sender, EventArgs e)
{
  // ...
}
4 Likes

Thanks guys. This did the trick. There are going to be some truly ecstatic gentlemen on the Production Floor.

Related question: I tried to apply this same technique to the Sales Order Acknowledgement custom SSRS report. I created a custom menu ID that launches the UIRpt.SalesOrderAckForm program. Then I made a customization to auto-print and set this specific menu item to use that customization in menu maintenance. However, even when I print an acknowledgement through the standard print option in the Actions Menu on an order, it does the auto-print as well. Why did the customization on my custom menu item also persist to the “base” menu which I assume is being called by the print acknowledgement function in Order? If this is unavoidable, any ideas how to overcome this?

Did you specified a specific personalisation in your menu maintenance for the Sales Order ack report Process ?
Verify tha tit is empty:

For us it works great. i created a context menu item where user richt clicks on the order and select the Ack report to print (it is a version for our shipping companies with no costs showing) and it prints and closes.

Pierre

Pierre,
This is exactly how I have my Context Menu report setup - and it prints great using the customization I specified. My issue is when I try to go the normal way, it also launches with the customization and I don’t want it to. Is there a menu maintenance entry for the standard Acknowledgement report?

Yes,

Under the Process section.
image

Interesting. Mine does not show there. However, I did find that if I create two menu items, it only refers to one when you print through the Order > Actions menu (seems like it might be the most recently created menu item). Once I figured that out, I set the other menu item to use the customization and for the context menu to point to this one. I have a working solution! Thanks again!!