Client script for fetching all the services present in a given Server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 07:59 AM
Hi,
I am new to servicenow and javascript.
I have a requirement where we need to stop all the services present in a selected server to stop them and perform patching.
So I want a client script to fetch all the services present in a server and should be displayed in the UI form.
So when I enter an IP address into Server Name field in the next field called Service Name it should show all the services present in that IP address in a drop down.
server_name: Server Name
service_name: Service Name
Any help or solution will be very helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 09:01 AM
Hi Ramya,
What you need to do is set up to ues an AJAX call to retrieve your data. To do that, you need a client callable script include that will do the lookup and return your data. The basic setup looks like this:
var ga = new GlideAjax('MySI'); //name of the script include
ga.addParam('sysparm_name', 'fetchTheData'); //name of the function in the script include
ga.addParam('sysparm_ip',"u_ip"); //additional parameter to be passed, you can havce as many as needed
ga.getXML(serverAnswer);
function serverAnswer(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
The AJAX call (ga.getXML(), includes the name of a callback function which will handle the result. Once answer is populated, you can add whatever other processing is needed to display your data.
To access the parameters that were passed along with the script include name and function, use this syntax
var theIP = current.getParameter("sysparm_ip");
where the argument is the name you gave the parameter when setting up the AJAX call in your client script.
AJAX runs asynchronously so that there is no freeze of the browser.
:{)
Helpful and Correct tags are appreciated and help others to find information faster