How to Send Event from Page Collection to Parent Page in UI Builder?

SundaramR
Tera Guru

Hi,

 

I'm trying to send a custom event from a Page Collection page to its Parent Page in UI Builder.

When using a Subpage, I was able to successfully emit and handle the event in the parent using the SEND MESSAGE event in the Variant Event Mappings. However, when using a Page Collection, I’m not seeing the same behavior.

Specifically, in the SEND MESSAGE Relay (Default) section of the Variant event mappings, I'm trying to add a SEND MESSAGE event — but this event isn't available for the Page Collection.

I followed the steps from this post:

https://www.servicenow.com/community/next-experience-forum/ui-builder-page-collection-bubble-event/m...

 

…but haven’t been successful in getting the event to bubble up from the Page Collection to the parent page.

Does anyone have the proper steps or workaround for sending custom events from a Page Collection to the parent?

 

adding image from subpage and page-collection body event.

 

Thanks in advance! 

6 REPLIES 6

MC30
Tera Guru

Hi Sundaram R,

 

You cant use "SEND MESSAGE" in a page collections variant event mappings,

So custom events from a page collection wont reach the parent page using the same method as subpages.

 

Recommended you to Use a client state to communicate. Below are the steps to implement:

 

Step1: Create a client state in the parent page

1. Go to the Parent page in UI builder.

2. In the right panel, click "Client State"

3. Create a new client state:

Name: collectionEvent

Type: Object

Default: {}

 

Step 2: Set the state from the page collection page

1. Open the page inside the page collection

2. select the component that will trigger the event (e.g a button)

3. Add an event handler:

Action: Set Client State.

Target State: collectionEvent

value:

 

 

{

"type: "MY_CUSTOM_EVENT,

"message": "Hello from page collection"

}

 

 

Step 3: Handle the event in the parent page. You can use two options here based on your feasibility

Option A: Use a view model

1. Add a view model to the parent page.

2. Use the below code:

export default function ViewModel ( { state } ) {
effect (() => {
if (state.collectionEcebt?.type === 'My_CUSTOM_EVENT') {
console.log('Received event:', state.collectionEvent.message);
//Handle event here
//Optional: Reset the state after handling
state.collectionEvenr = {};
}
}, [state.collectionEvent]);
return {};
}

 

Option B: Use Conditional Wrapper (No Code)

1. Add a Conditional Wrapper component.

2. Bind the condition to:

 

$client.state.collectionEvent.type === 'My_CUSTOM_EVENT'

 

3. Inside the wrapper, place any components or actions you want to trigger.

 

*This approach allows any page inside a page collection to communicate with the parent page using client state - a clean, supported workaround.

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Madhuri

 

@MC30  from page collection not able to see the client state variable created in the parent page. see the screen shot from page collection. may I know why this variable missing in the child page collection page?

 

image.png

 

Practically, it might not be possible for Page Collection to load client state parameter from parent page as this Page collection can be used multiple workspaces / pages.

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Page collection pages use controllers on the parent page to communicate so the only way to communicate from the PC page to the parent page is to call an event handler on the parent page's controller. 

Pre-yokohama release this restricts page collection communication to pages that have OOTB controllers, but in Yokohama controller building allows you to create your own custom controllers.