Client script for fetching all the services present in a given Server

Ramya SL
Tera Contributor

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.

1 REPLY 1

johnfeist
Mega Sage
Mega Sage

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.

 

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster