- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2016 11:03 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2016 08:28 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2016 02:34 PM
Hi Robert,
You can do both. So say you have a script which is something like below
sm = new sn_ws.RESTMessageV2("Rest Message Name", "Method");
// Rest Message Name - If you search in navigator by Rest Message Outbound you can define a new one there with all the information that you require like endpoint url, authentication and use midserver too.
In the Use midserver we can assign the default midserver.
// Method would be post, get , put etc...
response = sm.execute(); //to get response
If you want to do it by capability you can also do it based on a certain parameter or ip address etc..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2016 10:38 PM
Hi Venkat,
Thank you for the reply. I'm not using a REST message record (like # 3 in link below) because this integration has too many moving parts, but I am using the setMIDServer() method (like #5). It says I need to specify a mid server name (string), but I would like it to send it to any available mid server with the REST capability instead of specifying a single machine.
Scripting Outbound REST - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2016 08:28 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2016 10:50 AM
Hi Venkat,
Thank you. I was thinking that there might be a RESTMessageV2 method that selected by capability, but with your suggestion I could select one by capability that is up, set its name to a variable, and use the setMIDServer() method with that variable.