The CreatorCon Call for Content is officially open! Get started here.

Shantharao
Kilo Sage

Hello All,

 if you need to populate select box variable from a table, in this scenario below scripts will be helpful

 

ScriptInclude

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

getBuildingNamesByCity : function(){
var buildins = [];
var city = this.getParameter("sys_param_city");
var loc = new GlideRecord("u_geographical_hierarchy1");
loc.addQuery("u_city", city);
loc.query();
while(loc.next()){
buildins.push(loc.u_building.toString());
}

var dups = [];
var arr = buildins.filter(function(el) {
if (dups.indexOf(el) == -1) {
dups.push(el);
}
});

return dups.toString();
},

getFloorByBuildings : function(){
var floors = [];
var building = this.getParameter("sys_param_building");
var loc = new GlideRecord("u_geographical_hierarchy1");
loc.addQuery("u_building", building);
loc.query();
while(loc.next()){
floors.push(loc.u_floor_name.toString());
}

var dups = [];
var arr = floors.filter(function(el) {
if (dups.indexOf(el) == -1) {
dups.push(el);
}
});

return dups.toString();
},

type: 'assetRequisitionUtils'
});

find_real_file.png

 

OnChange Client Script

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.clearOptions('floor_asset_requisition');
g_form.addOption('floor_asset_requisition', '', '--None--');
return;
}
var ga = new GlideAjax('assetRequisitionUtils');
ga.addParam('sysparm_name', 'getFloorByBuildings');
ga.addParam('sys_param_building', newValue);
ga.getXML(HelloWorldParse);

function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
var floors = answer.toString().trim().split(',');
g_form.clearOptions('floor_asset_requisition');
g_form.addOption('floor_asset_requisition', '', '--None--');
for(var index = 0; index < floors.length; index++){
//alert(buildins[index]);
//return;
g_form.addOption('floor_asset_requisition', floors[index], floors[index]);
}
}

}

 

find_real_file.png

 

Thanks 

Version history
Last update:
‎01-28-2019 03:54 AM
Updated by: