How to call an event in my custom component from the UI Builder

Philippe Luickx
Tera Contributor

I have created a custom component and I want to trigger an event in that component from the UI Builder. Is it possible to call that event? I tried api.emit('EVENT') in a client script but that didn't work.

Otherwise I would have to watch a property? But not sure if that's even possible?

1 ACCEPTED SOLUTION

Ahh so components are built as properties in and events out, so I would expose a property that you want to monitor and then use your event in UIB to change a CSP you've bound to that property in UIB.

View solution in original post

6 REPLIES 6

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Philippe,

THere are a couple of extra steps you need to take when deploying the component to the instance in order to make it fire an event you can consume from UI Builder. I've got a blog and video on the subject here: https://developer.servicenow.com/blog.do?p=/post/quebec-ui-builder-custom-component-events/

Hi Brad,

Thanks again for answering! I've done these steps. But what I want to achieve is "the other way around". So emit an event from a script in the UI builder that then triggers an action in my custom component.

Ahh so components are built as properties in and events out, so I would expose a property that you want to monitor and then use your event in UIB to change a CSP you've bound to that property in UIB.

That makes sense. But how can you monitor a property? In vue there are watchers https://vuejs.org/v2/guide/computed.html#Watchers but couldn't find something similar for Now UI?

To clarify: what I try to accomplish is drawing markers on a map. For this I need to call a certain API, I can not implement this reactively...