How to Close the Window in which the Component is Shown

Description

A UX or Grid component opened in a window in a Desktop application can close the window when the component is submitted or a button is clicked.

Discussion

If you use a Grid or UX component in a Desktop Application and you open an Xdialog window that hosts a component, a common use case is to automatically close the host Xdialog window when data in the Grid is submitted or when a button is pressed in a UX.

Here is how you can do this:

This will only work in a desktop application. If the component can be used in both a desktop and web application, you will need to add additional checks to ensure that the JavaScript is not executed in a web environment.

Close the Window on Submit 

First, add this code to the Javascript Functions section in the component:

function closeXdialog() {
    var xb = [];
    xb.push('dim dlgtitle as c');
    xb.push('dlg_title = ui_dlg_query("dialog")');
    xb.push('dlg_title = filter_string(dlg_title,"GridComponentInXdialog_",crlf())');
    xb.push('ui_modeless_dlg_close(dlg_title)');
    xb = xb.join(';');
    genericXbasicUIFromWorkingPreview(xb);
}

Then, for a Grid component, add this code to the afterGridSubmit and afterRowSubmit Client-side events:

if(e.hasErrors == false) {
    closeXdialog();
}

If wanting to close a UX component after data is submitted, add this to the JavaScript returned by the afterDialogValidate event:

e.javascript = e.javascript + "closeXdialog();"

Close the Window when a Button is Clicked 

Add the closeXdialog() javascript function from the example above to the Javascript Functions of the component.

Then, add this code to a button in the component:

closeXdialog();

This method will work for buttons placed in both UX and Grid components.

Limitations

Desktop Applications Only