Can the Asynchronous Message Bus (AMB) be used directly within an Application (client-subscribe, server-publish)?

David Hubbard
Tera Guru

Hi

I am aware that ServiceNow uses it's Asynchronous Message Bus (AMB) for forum level field updates (record watcher?) and for Mid Server triggering.

But can it be used in a bespoke fashion within an Application, such that a client screen (Workbench panel?) may subscribe to a bespoke topic and a server-side script (on an Event?) can publish to the topic?

I can see there may be alternative ways of doing this (e.g. This community link) but that seems to rely on an external message broker setup (per client instance). 

If it is available for use, can you point me at documentations please?

Thanks

1 ACCEPTED SOLUTION

Hi Rishabh

Very helpful, thanks

I was a bit daunted looking at those scripts but think the key part was it showed how to get the message client from the amb variable. 

   function getChannelRW(table, filter) {
            var t = '/rw/default/' + table + '/' + getFilterString(filter);
            return amb.getClient().getChannel(t);
        }

The key being the "amb.getClient()" rather than "amb"

This change seems to have worked, with a successful subscribe. 

I guess in terms of my initial question the server-side publish part is down to table updates and appropriate subscriptions.

Thanks again for helping me out.    

P.S. For completeness I attach the angular-based reworking of the first link you sent which can work in a UI Script

View solution in original post

13 REPLIES 13

Rishabh Jha
Mega Guru

Hi David,

The events are asynchronous, so what's the use-case of having the listener on the client side?

We can create an event registry, and then publish to that event using: gs.eventQueue('event.name', gliderecord, param1, param2);

and then, we can have a Script action listening to that event, and running the desired business logic based on the event data.

Thanks & Regards,

Rishabh Jha

Aavenir (https://www.aavenir.com/)

David Hubbard
Tera Guru

Hi

The use-case for client side Websocket listener is where multiple users are viewing the same data screen (just for example - similar to say PPM Project Workbench screen (attached)).

...and where a data update happens (one user updates the data) then I would like to be able to capture that event (server-side) and get the data sent via WebSockets (AMB?) to all users on the appropriate screen (because they subscribed to the appropriate topic) to see a data update.

I am aware that I can process an event server-side, but my question was about propogating that event to multiple clients as required - I believe that ServiceNow use AMB for this record level updates (see 2nd attached, with WebSocket 101 messages between browser (subscribing) and server (publishing).

What I don't know is if this is a generally available feature of ServiceNow or something that is uses under-the-covers i.e. no API is provided for Appliction usage.  It would be neat if it was allowed e.g. by a bespoke topic.

 

find_real_file.png

 

find_real_file.png

Rishabh Jha
Mega Guru

Hi David,

I believe this is what you're looking for: 

https://community.servicenow.com/community?id=community_question&sys_id=b884c3a9dbd8dbc01dcaf3231f96...

If you're using a service portal UI, you can use spUtil.recordWatch() to listen to the changes made to a record, on the client side (refer: https://developer.servicenow.com/dev.do#!/learn/learning-plans/orlando/servicenow_application_develo...).

Thanks & Regards,

Rishabh Jha 

Aavenir (https://www.aavenir.com/)

David Hubbard
Tera Guru

Hi Rishabh

Thanks - that first link is potentially in the right area.  I can see that there is an "amb" variable on my app page, set by ServiceNow - however I get an Angular error

TypeError: "amb.getChannel is not a function"

I'm wondering if this is an un-published mechanism, which was looking to "emulate" how the portal "snRecordWatcher" object wrapper worked with AMB.  Potentially the amb api has moved on since that was posted (4 years ago). 

Are you aware of any API documentation for this?