Need help on building dynamic search box using bootstrap in Service portal

前提是你 提交于 2020-03-25 18:25:14

问题


I am currently working in Servicenow Serivce portal where it support Angular

I am able to create a Search box using bootstrap as shown below:

Server Code:

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
	
	try { 
	 
	 var r = new sn_ws.RESTMessageV2('coronaAPI', 'Default GET');
  
	 var response = r.execute();
	 var responseBody = response.getBody();
	 var httpStatus = response.getStatusCode();

	gs.log(responseBody + "respno");

			data.responseBody =responseBody; 
	var parser = JSON.parse(responseBody);
	
	var length = parser.locations.length;
	var nameArray = [];

	for(var i=0;i<length;i++){
		if(parser.locations[i].province != ""){
	  nameArray.push(parser.locations[i].country + '-' + parser.locations[i].province);
			
		}
		else
		{
		 nameArray.push(parser.locations[i].country);
			gs.info(parser.locations[i].country + "edlsfd");
	}
										}

	var countries = JSON.stringify(nameArray);
		data.countries = nameArray.map(function(text, i) {
		return {value: i+1, text: text}; //Incrementing i value with 1
	}); 

		}

	catch(ex) {
	 var message = ex.message;
		
}

})();

Initially i was trying with above script where i was increment to set the value of the option. I want to set the value which i receive from the responsebody, from the response body i get id and country initially i was pulling only country values now i am pulling both country & id into an object i want to set the country as an option and id as value.

With below code:

enter code here
for(var i=0;i<length;i++){
		var ob = {};
		if(parser.locations[i].province != ""){
		
	  ob.text = parser.locations[i].country + '-' + parser.locations[i].province;
		ob.id = parser.locations[i].id;
			
		nameArray.push(ob);							
		
		}
		else
		{
			ob.text = parser.locations[i].country;
		ob.id = parser.locations[i].id;
			
		 nameArray.push(ob);
		
	}
										}
	//gs.info(nameArray +"ffadsf");
	var countries = JSON.stringify(nameArray);
		gs.info(	countries + "adfsdfa");

Now i unable to pass value and country into below lines

data.countries = nameArray.map(function(text, id) {
		return {value: id, text: text};
	}); 

来源:https://stackoverflow.com/questions/60801221/need-help-on-building-dynamic-search-box-using-bootstrap-in-service-portal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!