Close Configurator via Code

I have a product configurator that I would like to close/exit automatically via code based on selections made by a user. So basically mimic the same function as the red cross button at the top-right corner of our screens. But I have been unable to use Environment.Exit(), Application.Exit() and Application.ExitThread() successfully as they close not just the configurator but the whole epicor application. Is there a way I can achieve this in c# in the configurator. Essentially a way to mimic the red cross button to close application in code will work too but I don’t know how to go about it.

Does anyone have any idea how to go about it?

This should work in a form customization.

this.csm.PersonalizeCustomizeManager.TopControl.FindForm().Close();

Thanks Jeremy, but I tried it doesn’t work because in this case “this” points to the TemporaryPageEventCollection instance and not the form itself.

You can create a class variable in the InitializeCustomCode method. Then just use the variable to call form.Close()

System.Windows.Forms.Form form;

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
		// End Wizard Added Custom Method Calls

        form = this.csm.PersonalizeCustomizeManager.TopControl.FindForm();
}

1 Like

You can’t customize a configurator screen.

If you have a control placed on the configurator page you should still be able to access the form methods however. The example below uses a group box.

var getfrm = (Ice.Lib.Framework.EpiGroupBox)Inputs.Section1.Control;
var frm = (getfrm.Parent).Parent.FindForm();
2 Likes

Thanks Evan!! That seems to work. I added frm.Close(); method after your code and it closes the form but its giving me the following error right after it closes the form:

Application Error

Exception caught in: Erp.UI.ConfigurationRuntimeEntry

Error Detail

Message: System.NullReferenceException: Object reference not set to an instance of an object.
at Ice.Lib.Framework.EpiTransaction.setEDVNotificationState()
at Ice.Lib.Framework.EpiTransaction.ResumeNotifications()
at Erp.UI.Cfg.TESTbef968eea7a74b13ac8039f9ee50a364.Controllers._QA3_TempController.ControllerResumeNotifications() in c:\Users\mimtiaz\AppData\Local\Temp\314\ConfigDump\Client_QA3_TempController.cs:line 1963
at Erp.Lib.Configurator.Runtime.SystemFunctionsLib.ResumeNotifications()
at Erp.UI.Cfg.TESTbef968eea7a74b13ac8039f9ee50a364._QA3_TempPageEventCollection.Page1Loaded(PageChangeArgs Args) in c:\Users\mimtiaz\AppData\Local\Temp\314\ConfigDump\Client_QA3_TempPageEventCollection.cs:line 247
at Erp.Shared.Lib.Configurator.MethodCollection1.Invoke(String methodName, TMethodArgs args) at Erp.Lib.Configurator.Runtime.ConfigurationController1.TriggerPageEvent(Int32 callerPageSeq, PageChangeArgs args)
at Erp.Lib.Configurator.Runtime.ConfigurationController`1.PageLoaded(PagingDirection direction)
at Erp.UI.Cfg.TESTbef968eea7a74b13ac8039f9ee50a364.Controllers._QA3_TempController.Erp.Lib.Configurator.Runtime.IConfigurationController.PageLoaded(PagingDirection )
at Erp.UI.App.ConfigurationRuntimeEntry.Transaction.StartConfiguration(Boolean& needsUserInput, String inSmartString)
Program: Erp.UI.ConfigurationRuntimeEntry.dll
Method: StartConfiguration

Client Stack Trace

at Erp.UI.App.ConfigurationRuntimeEntry.Transaction.StartConfiguration(Boolean& needsUserInput, String inSmartString)
at Erp.UI.App.ConfigurationRuntimeEntry.Transaction.GetNextConfiguration(Boolean& needsUserInput, Boolean overrideLastConfig, Boolean fromSaveConfiguration)
at Erp.UI.App.ConfigurationRuntimeEntry.ConfigurationRuntimeForm.LaunchForm(Object options)

Does this have to do with the event handler? If yes, is there a way to dispose it?

Pretty sure you need to use the frm.Dispose() before the frm.Close() or frm.CloseOnFormCancel()

MainController.BeginInvoke(new MethodInvoker(MainController.Close));

https://www.epiusers.help/t/how-to-close-maincontroller-in-form-load/101396

Have a good day! Good luck! :smiling_face_with_three_hearts: :smiling_face_with_three_hearts:

1 Like