Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

RESTMessageV2 set MID Server by capability

Robert Beeman
Kilo Sage

When using scripted REST messages, is it possible to have it use the default MID server or to specify a capability if you have multiple MID servers. The setMIDServer method description sounds like I need to specify a specific MID server by name.

1 ACCEPTED SOLUTION

Hi Robert,



Then may be something like this would be useful for you



var gr =   new GlideRecord('ecc_agent_capability_m2m');


gr.addQuery("capability", "REST");


gr.query();


while(gr.next()) {


  if(gr.agent.status == "Up") {


  gs.log("Available Mid Servers" + gr.agent.name);


  }


}



If you are using Rest message in a client script then you might have to create a script include make a ajax call for the above script.


You can return the first agent name that is active and that should take care. You might have to add the rest capability to the mid server for this code to work.



Hope it helps.


View solution in original post

5 REPLIES 5

phsdm
Giga Expert

The MIDServerSelector class gives you a hook into the the algorithm to select mid servers based on IP Ranges and Capabilities.   This might provide more stable behavior as you migrate to clusters or otherwise complicate your mid server selection configuration.