How to get GUID of one form from another form in epicor?

I have tried but got run time error for below code as GUID not found type of error

from child form. coded in following form level event - on closing of child form , i need to either hide/close parent form too.

private void ToDoForm_Closing(object sender, System.ComponentModel.CancelEventArgs args)
	{
		// Add Event Handler Code
EpiBaseForm frm = (EpiBaseForm)(csm.GetNativeControlReference("GUID"));

frm.Close();
	}
//GUID - parent form's GUID

How to get through it?

Forms accessed from other forms isn’t totally straightforward. There may be a simpler way for parent-child forms, but so far I’ve usually ended up iterating through the forms collection to find the one that’s relevant.

Thanks a ton. Can u share me the code for reference??

foreach (Form f in Application.OpenForms)
{
	if (true) //some check to make sure this is the right form
	{
		EpiBaseForm ef = (EpiBaseForm)f;		
	}
}

That’s the generic code I use, but I admit I haven’t hung anything mission-critical off it. Someone else know better if there’s a more direct way of accessing a particular form.

Thank you very much. Mr.Daryl Hewison.
Here is my code snippet.

private void ToDoForm_Closing(object sender, System.ComponentModel.CancelEventArgs args)
	{
		// Add Event Handler Code
		foreach (Form f in Application.OpenForms)
		{
		   MessageBox.Show(f.Name);
			if (f.Name == "ReqEntryForm") //some check to make sure this is the right form
			{
				//EpiBaseForm ef = (EpiBaseForm)f;
			    f.Close();
			}
		}
	}

I am close to my required answer.
But i could not close the form.
Here is the exception i am getting at run time

image

image

Any suggestion?

This is where I’d start being quite careful, personally.

There are things you can’t do within an enumeration, and typically removing an element entirely is one of them. If you step out of the enumeration and close from outside the loop you may be OK, but I’m not sure how Epicor reacts to shutting down forms that way.

Yeah you are right. Fingers crossed…

I have used this BAQ, it is set to pull by user name
I uploaded the BAQ

rpthist.baq (12.9 KB)

Thanks for the BAQ. I have imported. But could not get what you are trying to say. can you please elaborate?.

It only pulls in Guid for the current user ID is what I meant to say.

So I have to do a print preview of the report I am working on to get the GUID

Hi as you suggest i fixed by closing outside the loop by creating reference to loop. code as follows. it works fine:) thanks

Form formtoclose=null;
        foreach (Form f in Application.OpenForms)
        {
			
            if (f.Name == "ReqEntryForm")
            {
                formtoclose = f;
            }
        }
        if(formtoclose!=null)
        formtoclose.Close();
1 Like

Sorry this idea does not works for me. any way thanks for your time

Hi but still while closing the form i am getting object reference error . may i know why and how to resolve it but collection error rectified

image

image

I wouldn’t be able to answer without working through the same thing myself, which I haven’t done.

As I suggested, Epicor may have trouble with simply closing the forms. My guess is that when you do so, there’s still some code running which is expecting that form to be there. You may be able to find a better place to do the closing, or you may have to delay the close somehow or hide instead of close or something, but the application probably isn’t going to make it easy.

I have delayed/ tried hide nothing works…

Can you explain what you are trying to do? and from where?

My requirement :

Deploy the Requisition To-Do List on a separate stand-alone menu item instead of having it as an action item in the Requisition Entry screen.

In the requisition Entry i created one customization. In the page load of the customization i have done this code

oTrans.InvokeToDoList();

So it is launching “requisition todolist” , but while closing todolist , requisition entry opens.

I want to close requisition entry.

so i coded the following codes on page load to close the requisition entry. It is closing but with error

Form formtoclose=null;
foreach (Form f in Application.OpenForms)
{


        if (f.Name == "ReqEntryForm")
        {
            formtoclose = f;
        }
    }
    if(formtoclose!=null)
    formtoclose.Close();



EpiBaseForm frm = (EpiBaseForm)(csm.GetNativeControlReference(“GUID”));

frm.Close();

error screenshots i already uploaded in this thread. please browse up the post and check.

is there any way to close the form using menu id???

Plz share some sample code or suggestion?

What you are trying to do is highly un-usual can I ask the million dollar question?

Why?

The issue you are running into is that there is some code that runs on form close which expects certain values to be loaded (which aren’t)
You may be better off just doing this outside of Requisition Entry. Invoke the TODO list directly from a different screen.
However I always go back to the why? What is the need being addressed? and is it reasonable?

Our client requirement to make this as a stand alone. I dont know the reason behind this. yeah it is very unusual But?..

How to directly invoke todolist from different screen.???/ In which method?

The same way
" oTrans.InvokeToDoList();"