UI Builder Page Collection Bubble Event

nwilliam
Tera Contributor

I have a viewport using a page collection that I would like to have a button that bubbles up an event to the main page.

I tried the "bubbling up" method here: https://www.youtube.com/watch?v=PwZLd2phUZQ

But they were using viewports/sub pages so I think what worked there does not work with page collections.  How would I go about getting a button to trigger an event on a parent page from a page collection viewport?

On this episode, join Brad, Chuck, and Earl as they explore viewports in UI Builder in the Rome release. Useful Links: * Community Live Stream: Document IDs https://community.servicenow.com/community?id=community_blog&sys_id=d3fec975db2d9410d58ea345ca9619e0 * Platform Academy Series ...
1 ACCEPTED SOLUTION

Hi @IronPotato

do you know how to perform this miracle?


I am having the same issue as @nwilliam . I managed passing params down to the page collection page using a controller, but my event won't bubble up from the child page (page collection) to the parent page. I had the same issue when creating custom components, but it is possible to fix it by adding the event manually in the "eventMappings" (page definition) of that component. Unfortunately this does not seem to work for Viewport Components with Page Collections.

 

On the child page I added a dispatch event on the body, that is triggered by a click event on a button:

fujan_0-1733846963507.png

fujan_1-1733847010823.png

On the parent page I added the same event in the body's handle event section:

fujan_2-1733847221235.png

Now calling this handled event like in the above video does not work for me.

 

 



 

View solution in original post

13 REPLIES 13

IronPotato
Mega Sage

Hi, @nwilliam,

 

it works for page collections as well but to setup this correctly is miracle. What type of event are you using on child pages and what on parent page?

Hi @IronPotato

do you know how to perform this miracle?


I am having the same issue as @nwilliam . I managed passing params down to the page collection page using a controller, but my event won't bubble up from the child page (page collection) to the parent page. I had the same issue when creating custom components, but it is possible to fix it by adding the event manually in the "eventMappings" (page definition) of that component. Unfortunately this does not seem to work for Viewport Components with Page Collections.

 

On the child page I added a dispatch event on the body, that is triggered by a click event on a button:

fujan_0-1733846963507.png

fujan_1-1733847010823.png

On the parent page I added the same event in the body's handle event section:

fujan_2-1733847221235.png

Now calling this handled event like in the above video does not work for me.

 

 



 

Hi @fujan  and @nwilliam ,

 

here's the step by step guide.

 

1. Add Handled Event (first) on your Parent Page (examples MESSAGE, NEW_MESSAGE, in my case TOTAL) with payload variables (example name: message, label: Message, type: String) and save the page.

IronPotato_3-1733910613769.png

 

2. Go to your child page (refresh page if you have it open in separate TAB) and go to your component where you want to trigger event to parent. Add event handler and select your new event from Inherited event handlers and save the page. (THIS WILL CREATE EVENT RELAY ON YOUR CHILD PAGE WHICH YOU WILL VERIFY BY GOING INTO PAGE EVENTS. IT WILL ADD "Relay" SUFFIX TO YOUR EVENT ON PAGE LEVEL AND IT WILL ALSO CREATE DISPATCHED EVENTS AUTOMATICALLY).

IronPotato_2-1733910588434.png

3. Under your new message relay (in my example TOTAL Relay (Default)) add your event and pass there @payload.message (your payload variable) if its not already added for you.

IronPotato_4-1733910728272.png

IronPotato_7-1733911897333.png

 

4. Go back to your parent page and under page events add your event under Page event mappings. This will add this event on page level where you can execute/refresh/log anything you need. Simple test would be to add client script where you just simply console.log('this is from child');

IronPotato_5-1733910777979.png

5. Now refresh your Application Page and test the result.

We are done!

 

EXTRA BONUS TIP: once relay event is created it will add sys_id into this event and you can event trigger them from client scripts.

IronPotato_6-1733911589243.png

You can invoke them like this: api.emit('TOTAL_RELAY_eca5c71a47f37d109fe397da116d43f7', {

message: 'Hello World!'

})

 

Hope that helps. Please make this post helpful if you it will work for you.

🙂

 

 

Thank you @IronPotato for the great step by step guide!

I was able to do it this way for the normal "viewport", but if I choose "Page collections" I don't get the parent's event in my "Inherited event handlers" (Step 2).

 

My work around is to first create a viewport, do step 1 and 2, then create another one using "Page collections" and manually add the previously created events in the page definition of that child page:

fujan_0-1733926448418.png

Then I can follow your steps 3-5 and it works!

 

I'm on Washington btw.