How to communicate via cluster mid server in ServiceNow

Akilprasath Cha
Tera Contributor

Hi Team,

 

Earlier I was using the actual mid server name to communicate with the external calls below I attached the sample code.

 

            if (mid_server != "") {
				r.setMIDServer(mid_server);
                r.setEccParameter('skip_sensor', 'true');
            }

 

But, now we are trying to communicate using cluster mid server for external communication. I tried the same thing by replacing the Mid Server name with the Cluster Mid Server Name. It is not working as expected. Below I have attached the Cluster screen shot.

 

AkilprasathCha_0-1683027414599.png

 

Help me to communicate via Cluster Mid Server Name using the sn_ws.RESTMessageV2();

 

Thanks In Advance

2 REPLIES 2

Community Alums
Not applicable

Hi @Akilprasath Cha ,

To communicate via a cluster mid server in ServiceNow, you can use the following steps:

  1. Identify the mid server(s) in the cluster that you want to communicate with. You can do this by navigating to "MID Servers" in the ServiceNow instance, and checking the "Cluster" column.

  2. Use the "gs.getMIDServer()" method to retrieve the name of the active mid server in the cluster. This method returns the name of the current mid server that is running the script.

  3. Use the "gs.getClusterMIDServerNames()" method to retrieve the names of all the mid servers in the cluster. This method returns an array of mid server names.

  4. Use the "GlideHTTPClient" object to create an HTTP client object to communicate with the desired mid server. Set the "targetCluster" property of the GlideHTTPClient object to the name of the mid server cluster.

  5. Use the "GlideHTTPRequest" object to create an HTTP request object to send a request to the desired mid server. Set the "midServer" property of the GlideHTTPRequest object to the name of the target mid server.

  6. Use the "send()" method of the GlideHTTPRequest object to send the request to the desired mid server.

  7. Process the response from the mid server as needed.

 

Hi @Community Alums 

 

Did you have any sample code to verify that?

 

Lets if we have two different cluster then how this will work?

 

Thanks