The Zurich release has arrived! Interested in new features and functionalities? Click here for more

UI Macro client side communication with external system

lordstizzlor
Tera Expert

 

Hello,

I have an inquiry concerning UI Macros and integration with external systems. We operate a system developed in NodeJS, capable of generating various types of data, including snapshots and chat messages. Once the user finalizes the data generation process, I have the capability to transmit this data back to our ServiceNow instance via REST API calls. The snapshots are uploaded and stored as attachments within ServiceNow, linked to specific incidents.

My question is: Is it feasible to transmit continuous status updates (like a upload progress) from our NodeJS system to ServiceNow and have these updates reflected in the UI Macro, functioning similarly to a Publish/Subscribe (Pub/Sub) model?

 

I have tried these types of Communication: 

 - REST Call to a Scripted Rest API firing an event to sys_event queue

 - WebSocket Connection from the UI Macro to the external system

Unfortunatly with no luck, can anyone help me on this topic ? 

1 ACCEPTED SOLUTION

lordstizzlor
Tera Expert

Okay so i found a solution by myself. I am posting this in case anyone needs this information. 

So ServiceNow communicates via Websocket between ServiceNow Client and ServiceNow Server. The Websocket connection can be seen when you go to an incident and debug the application with developer tools in chrome or something else. As you can see in the screenshot there is a WebSocket Connection called amb (Asynchronous Message Bus). The ServiceNow Server sends data back and forth in channels via this Bus. On the Client-Site we can subscribe to a Channel with Code like this: 

 

 if (incidentGlideRecord.next()) {
	        var customSysId = incidentGlideRecord.getValue('customTableValue');
	        var object = 'sys_id=' + customSysId;
	        var encryptedObject = btoa(object);
	        var channelName = '/rw/default/somecustomtable/' + encryptedObject;
	        var channel = amb.getClient().getChannel(channelName);
	        channel.subscribe(handleMessage);
	    };

 

Please note the following.  the rw stands for recordWatcher. and the encryptedObject is the sys_id of a record in this table for example you want to see changes on a incident you have to subscribe to the url /rw/default/incident/<EncryptedSysId> of the incident record. 
With this you are able to send an upload progress or other live updates to a record and react from the client site accordingly. 

 

View solution in original post

1 REPLY 1

lordstizzlor
Tera Expert

Okay so i found a solution by myself. I am posting this in case anyone needs this information. 

So ServiceNow communicates via Websocket between ServiceNow Client and ServiceNow Server. The Websocket connection can be seen when you go to an incident and debug the application with developer tools in chrome or something else. As you can see in the screenshot there is a WebSocket Connection called amb (Asynchronous Message Bus). The ServiceNow Server sends data back and forth in channels via this Bus. On the Client-Site we can subscribe to a Channel with Code like this: 

 

 if (incidentGlideRecord.next()) {
	        var customSysId = incidentGlideRecord.getValue('customTableValue');
	        var object = 'sys_id=' + customSysId;
	        var encryptedObject = btoa(object);
	        var channelName = '/rw/default/somecustomtable/' + encryptedObject;
	        var channel = amb.getClient().getChannel(channelName);
	        channel.subscribe(handleMessage);
	    };

 

Please note the following.  the rw stands for recordWatcher. and the encryptedObject is the sys_id of a record in this table for example you want to see changes on a incident you have to subscribe to the url /rw/default/incident/<EncryptedSysId> of the incident record. 
With this you are able to send an upload progress or other live updates to a record and react from the client site accordingly.