The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to populate multiline text values based on the list collecter values.

shrinivasprasad
Tera Expert

Hi Community,

I am trying to populate multivalue text box values bassed on the list collecter values which is referenced to the cmdb_ci_server table, here if i select multiple server names then i should get respective server ips in the server ip filed.

find_real_file.png

Appricated for the quick response.

Thanks,

Shrinivasprasad

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

As mentioned you can use onChange + GlideAjax approach

sample working script here; enhance for your case

Populate Email Addresses of users selected in List Collector variable to Multi Line Text Variable

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Prasad Pagar
Mega Sage

Hi @shrinivasprasad 

You can try writing onchange client script on ServerNames field and then script include to get Server IPs to populate.

Did you tried any script already?

Thank you
Prasad

Hi Parag,

yes, i try below code but i didnt get expected result.

script includes.

var PopulateUserTimeZone = Class.create();
PopulateUserTimeZone.prototype = Object.extendsObject(AbstractAjaxProcessor, {

populateTZ: function() {

var ciArr =[];
var cis = this.getParameter('sysparm_cis');
var ci = new GlideRecord('cmdb_ci_server');
ci.addQuery('sys_id', 'IN',name);
ci.query();
while(ci.next()){
ciArr.push(ci.source_server_ip.toString());
//if you want the used_for values comma-separated use the line above
//or if you want the used_for values each on one line in the text field
//then use the line below
ciArr.push(ci.source_server_ip.toString() + '\n');
}

return ciArr.join(',');
},

type: 'PopulateUserTimeZone'
});

client script:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var ga = new GlideAjax('PopulateUserTimeZone');//name of the Script Include
ga.addParam('sysparm_name', 'populateTZ');//name of the function in the Script Include
ga.addParam('sysparm_cis', newValue);
ga.getXML(getCI);

function getCI(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('source_server_ip', answer);//name of your text variable
}
}

Did you tried adding logs into Script include and alerts in Client script?

Hope server ip's are present for selected values. 

@shrinivasprasad 

update as this

var PopulateUserTimeZone = Class.create();
PopulateUserTimeZone.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	populateTZ: function() {
		var ciArr =[];
		var cis = this.getParameter('sysparm_cis');
		var ci = new GlideRecord('cmdb_ci_server');
		ci.addQuery('sys_id','IN',name.toString());
		ci.query();
		while(ci.next()){
			ciArr.push(ci.source_server_ip.toString());		
		}
		return ciArr.join('\n');
	},

	type: 'PopulateUserTimeZone'
});

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader