Need Help on how to execute .js file in MID Server via MID Server script include?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 03:36 AM
We have a code in .js format file stored at MID Server. We are trying to execute that piece of java script via MID Server script include which we failed multiple times.
Could you please help us with process to achieve this functionality
Can we RUN Java script code at MID Server from ServiceNow script file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 08:46 AM
Hi,
Use below link and it answered similar to your question.
Suresh.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 11:45 PM
Hi Pushpa,
Yes, you can run JavaScript code stored on a MID Server from a ServiceNow script include. To do this, you'll need to create a script include in ServiceNow and use the GlideHTTPRequest class to make a call to the JavaScript file on the MID Server.
1.Create a script include in ServiceNow with the following code:
var GlideHTTPRequest = Class.create();
GlideHTTPRequest.prototype = Object.extendsObject(AbstractAjaxProcessor, {
runJSFileOnMIDServer: function() {
var midServerURL = 'https://<MID_SERVER_IP>:<PORT>/<PATH_TO_JS_FILE>';
var response = this.getURL(midServerURL, null, null, {});
return response;
}
});
Note: Replace <MID_SERVER_IP>, <PORT>, and <PATH_TO_JS_FILE> with the appropriate values for your MID Server and JavaScript file.
2. In the business rule or script include where you want to run the JavaScript code, use the following code:
var http = new GlideHTTPRequest();
var response = http.runJSFileOnMIDServer();
This will make a call to the JavaScript file on the MID Server and return the response. You can then use the response variable in your ServiceNow code to process the results of the JavaScript code.
Note: Make sure that the MID Server is properly configured and has access to the file system where the JavaScript file is stored. You may also need to configure the MID Server to allow access to the file system from the ServiceNow instance.