Close a component after completing an action#
Automatically close a Lightning component and return to the Context Panel Home screen after completing an action.
What this feature does#
By default, users must click the Back button to exit a Lightning component and return to the Context Panel Home screen.
This feature allows the component to close automatically after completing an operation, such as saving or updating a record.
This is especially useful for components with long forms, where manually navigating back can interrupt the user workflow.
How it works#
To close a component programmatically, the component must notify Context Panel that it has completed its operation.
This is done by firing the rg:finish event.
When Context Panel receives this event, it can:
Close the component and return to the Home screen
Display a notification
Refresh activities or related data
Trigger additional post-action behavior
Before you begin#
This feature applies to Lightning components that are already integrated with Context Panel.
If your component is not yet integrated, complete the configuration described in:
Lightning web component configuration#
To enable this behavior in a Lightning web component:
Define event parameters. For a complete list of available parameters, see rg:finish event parameters.
// Parameters passed to Context Panel after the operation is complete. // Adjust these values based on your component behavior. const finishEventParams = { // Custom notification displayed in the Context Panel notificationMessage: `New Task "${createdTask.Subject}" was created.`, // IDs of created activities (enables "View it now" action) createdActivityIds: [createdTask.Id], // Reload activity list to reflect the newly created record reloadActivities: true };
Create the
rg:finishevent.// Do not change the event name. // Context Panel listens for the exact event name "rg:finish". const finishEvent = new CustomEvent("rg:finish", { detail: finishEventParams });
Dispatch the event
// Dispatch the event after the operation is complete // (for example, after a successful save or update) this.dispatchEvent(finishEvent);
Aura component configuration#
To enable this behavior in an Aura component, create and fire a custom rg:finish event.
Create an Aura event bundle. The folder and file names must match the event reference (
type="c:rgFinish").aura/ └── rgFinish/ └── rgFinish.evtDefine the event. For a complete list of available event parameters, see rg:finish event parameters.
<aura:event type="COMPONENT" description="RG finish event"> <!-- Custom notification displayed in the Context Panel --> <aura:attribute name="notificationMessage" type="String" /> <!-- IDs of created activities --> <aura:attribute name="createdActivityIds" type="String[]" /> <!-- Reload activity list in the Context Panel --> <aura:attribute name="reloadActivities" type="Boolean" /> </aura:event>
Register the event in the component markup. Do not change the event name. Context Panel listens for the
rg:finishevent.<!-- Register the event so it can be fired from this component --> <aura:registerEvent name="rg:finish" type="c:rgFinish"/>
Implement the event in the JavaScript controller.
// Get the registered event instance var finishEvent = component.getEvent("rg:finish"); // Parameters passed to Context Panel after completion finishEvent.setParams({ // Custom notification displayed in the Context Panel notificationMessage: "New Task \"" + createdTask.Subject + "\" was created.", // IDs of created activities (enables "View it now" action) createdActivityIds: [createdTask.Id], // Reload activity list to reflect the new record reloadActivities: true }); // Fire the event after the operation is complete finishEvent.fire();