Notifications

20 views

Overview

This Article will demonstrate on configuring MID Selection Override filter for Cloud Operations to go through specific MID server.

MID Override

  • Login to the Instance 
  • Impersonate with the user have Admin Privileges 
  • Make sure the Application is Cloud API 
  • Navigator >> System MID Server  >> MID selector Override 
https://<Instancename>.service-now.com/mid_selector_override_list.do 
  • MID selector Override  >> Create New >> 

Example Script

Example 1 

context = JSON.parse(context);
//Use a specific mid server for 'vSphere Compute API' Cloud API
if(context['capi_impl_name'] == 'vSphere Compute API'){
var midList = [];
for(mid = 0; mid <= defaultSelectedMIDList.length; mid++){
if(defaultSelectedMIDList[mid].name == 'MID NAME')
midList.push(defaultSelectedMIDList[mid]);
}
return midList;
}

Example 2 

context = JSON.parse(context);

//Use a specific mid server for 'ListSubscriptions' operation   >>>>> Choose the Operation 
if(context['capi_method_name'] == 'ListSubscriptions'){      
var midList = [];
for(mid = 0; mid <= defaultSelectedMIDList.length; mid++){
if(defaultSelectedMIDList[mid].name == '<MID_SERVER_NAME>')
midList.push(defaultSelectedMIDList[mid]);
}
return midList;
}

if (defaultSelectedMIDList.length > 0)
return defaultSelectedMIDList;

// Check if this is cloud capability - if not nothing to do
if (!hasCloudCapability(requestedParameters.capabilities))
return defaultSelectedMIDList;

// get first non cloud capability (e.g AWS) - there should be only one more
var capability = getNonCloudCapability(requestedParameters.capabilities);
if (JSUtil.nil(capability)) {
gs.warn("MID Selection filterOnCapability could not find a capablity for provider!");
return defaultSelectedMIDList;
}

// Get mid with AWS capability
var mids = getMidsWithCapability(capability);

if (mids.length > 0)
return mids;

mids = getMidsWithCapability('Cloud Management');

getMidsWithoutCapability(mids, capability);
return mids;

//
// INNER FUNCTIONS
//

//
// Do we have the Cloud capability in the list?
//
function hasCloudCapability(capabilities) {
for(var j in capabilities) {
if(capabilities[j].capability == 'Cloud Management');
return true;
}

return false;
}

//
// Get the first non cloud capability (e.g. AWS)
//
function getNonCloudCapability(capabilities) {
for(var j in capabilities) {
if(capabilities[j].capability != 'Cloud Management')
return capabilities[j].capability;
}

return null;
}

//
// Get the mids with this specific capability
//
function getMidsWithCapability(capability) {
var selectedMids = [];
for (var i in candidateMIDList) {
//Get all capabilities assign to a MID server
var capabilities = candidateMIDList[i].capabilities;

for(var j in capabilities) {
if('' + capabilities[j].capability == '' + capability &&
JSUtil.nil(capabilities[j].value))
selectedMids.push(candidateMIDList[i]);
}
}

return selectedMids;
}

//
// Filter out the mids with certain capability (Check name only, ignore value)
//
function getMidsWithoutCapability(mids, capability) {
for (var i = 0; i < mids.length; i ++) {
for (var j = 0; j < mids[i].capabilities.length; j ++) {
if (mids[i].capabilities[j].capability + '' == capability + '') {
mids.splice(i, 1);
}
}
}
}

Note: Above mentioned scripts are only example, users need to modify according to the requirement,  if any further questions or more information, please communicate with ServiceNow Technical support Team. 

Additional Information

Refer: Override the MID Server selection filter

Article Information

Last Updated:2019-06-13 04:22:35
Published:2019-05-23
001.jpg