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

I want to make the floor field dependent on room type field

avinashdubey103
Tera Guru

Hi,

I have a requirement to make the floor field dependent upon the room type:
Means we select dining room then only floor that have dining room should come. 

 I am trying to update this client controller code :

function updateFloorList(action, building, wing) {
c.server.get({
building: building,
wing: wing,
action: action
}).then(function(response) {
c.floorList = response.data.floors || response.data.wfloors;
});
}


As :

function updateFloorList(action, building, wing, roomType) {
   var roomTypeFilter = c.clientFilterStrings[roomType] || ""; 
   c.server.get({
       building: building,
       wing: wing,
       action: action,
       roomTypeFilter: roomTypeFilter // Pass the roomTypeFilter as a parameter
   }).then(function(response) {
       c.floorList = response.data.floors || response.data.wfloors;
   });
}:

But this approach is not working 

The corresponding server side code :

(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.catalog_sysId = $sp.getParameter('sys_id');
data.category_sysId = $sp.getParameter('category_sys_id');
data.sysId_advanced_location_view = gs.getProperty('cat_item_with_advancrd_location');
data.raanana_sysid = gs.getProperty('Raanana_new_Buidlings_sysid');
var loc = new Facility_Ticketing_Location_data_helper();
var filters = gs.getProperty('facilities.roomtype.filters'); //Property for roomtype filters.
data.prevLocation = input ? input.location : '';
data.qrLocation = $sp.getParameter('location');
data.isFromLocationPopup = input ? input.isFromLocationPopup : '';
data.cat_item = $sp.getParameter('sys_id');
data.Disable_room_type_select = false;
data.properties = loc.getMappingProperties(data.cat_item, data.category_sysId);
data.default_room_type = data.properties.defaultRoomType;
//var bldg;
if (!input || (input && input.isFromLocationPopup) || (input && input.action == "changeLocationByUser")) {
data.filterStrings = JSON.parse(filters);
data.cat_item = $sp.getParameter('sys_id');
data.Disable_room_type_select = false;
data.properties = loc.getMappingProperties(data.cat_item, data.category_sysId); //getting Location setup for Item's category
if (data.properties.displayEdit == "true" && !input.isFromLocationPopup) {
data.showAdvancedLocation = false;
data.showLocation = true;
} else {
data.showAdvancedLocation = true;
data.showLocation = false;
}
if (data.properties.roomTypeDisable == "true") {
data.Disable_room_type_select = true;
}
/* if(data.sysId_advanced_location_view.indexOf(data.catalog_sysId) != -1){
data.showAdvancedLocation = true;
data.showLocation = false;
}*/

data.default_room_type = data.properties.defaultRoomType;
data.roomTypeList = data.properties.roomTypeList;
data.building = {
"value": "",
"displayValue": "",
"name": "building"
};
data.wing = {
"value": "",
"displayValue": "",
"name": "wing"
};
data.floor = {
"value": "",
"displayValue": "",
"name": "floor"
};
data.room = {
"value": "",
"displayValue": "",
"name": "room"
};

//getting QR location for setting default Location
var user = '';
var grLoc = '';
if (data.qrLocation || data.prevLocation) {
grLoc = new GlideRecord('cmn_location');
grLoc.get(data.qrLocation || data.prevLocation);
} else {
var id = gs.getUserID();
user = new GlideRecord('sys_user');
user.get(id);
}
//getting user's information for setting default Location
if (user || grLoc) {
data.my_location_id = user ? user.location.sys_id.toString() : grLoc.sys_id.toString();
data.my_location_name = user ? user.location.name.toString() : grLoc.name.toString();
data.my_building_id = user ? user.location.u_building.sys_id.toString() : grLoc.u_building.sys_id.toString();
data.my_building_name = user ? user.location.u_building_name.getDisplayValue() : grLoc.u_building_name.getDisplayValue();
data.my_wing_name = user ? user.location.u_wing_name.getDisplayValue() : grLoc.u_wing_name.getDisplayValue();
data.my_floor_name = user ? user.location.u_floor_name.getDisplayValue() : grLoc.u_floor_name.getDisplayValue();
data.my_room_name = user ? user.location.u_room_label.getDisplayValue() : grLoc.u_room_label.getDisplayValue();
data.my_room_type_name = user ? user.location.u_room_type_name.getDisplayValue() : grLoc.u_room_type_name.getDisplayValue();
if (data.my_location_name == '' || data.my_building_name == '' || data.my_wing_name == '' || data.my_floor_name == '' || data.my_room_name == '' || data.my_room_type_name == '') {
data.showAdvancedLocation = true;
data.showLocation = false;
}
data.location = {
"value": data.my_location_id,
"displayValue": data.my_location_name,
"name": "location"
};
if (data.qrLocation || data.prevLocation) {
data.my_room_id = grLoc.u_room_label.getValue();
data.my_wing_id = grLoc.u_wing_name.getValue();
data.my_floor_id = grLoc.u_floor_name.getValue();
} else {
//getting Default Wing of User
var wingRef = new GlideRecord('cmn_location');
wingRef.addEncodedQuery('u_location_type=Wing^u_building=' + data.my_building_id + '^u_wing_name=' + data.my_wing_name);
wingRef.query();
while (wingRef.next()) {
data.my_wing_id = wingRef.sys_id.toString();
}
//getting Default Floor of User
if (data.my_floor_name != '') {
var floorRef = new GlideRecord('cmn_location');
if (data.my_wing_name == null || data.my_wing_name == "") {
floorRef.addEncodedQuery('u_location_type=Floor^u_building=' + data.my_building_id + '^u_floor_nameLIKE' + data.my_floor_name);
} else {
floorRef.addEncodedQuery('u_location_type=Floor^u_building=' + data.my_building_id + '^u_wing_name=' + data.my_wing_name + '^u_floor_nameLIKE' + data.my_floor_name);
}

floorRef.query();

while (floorRef.next()) {

data.my_floor_id = floorRef.u_floor_code.toString();
data.my_floor_name = floorRef.u_floor_name.toString();
}
}
//getting Default Room of User
var roomRef = new GlideRecord('cmn_location');
roomRef.addEncodedQuery('u_location_type=Room^u_building=' + data.my_building_id + '^u_wing_name=' + data.my_wing_name + '^u_floor_code=' + data.my_floor_id + '^u_room_label=' + data.my_room_name + data.filterStrings[data.default_room_type]);

roomRef.query();
while (roomRef.next()) {
data.my_room_id = roomRef.sys_id.toString();
}
}
data.building.value = data.my_building_id;
data.wing.value = data.my_wing_id;
data.floor.value = data.my_floor_id;
data.room.value = data.my_room_id; //!input.isFirstLocationPopupLoading?input.room.value:

data.building.displayValue = data.my_building_name;
data.wing.displayValue = data.my_wing_name;
data.floor.displayValue = data.my_floor_name;

data.room.displayValue = data.my_room_name; //!input.isFirstLocationPopupLoading?input.room.displayValue:

data.defaultWings = loc.getWings(data.my_building_name);
data.defaultFloors = loc.getFloors(data.my_building_name, data.my_wing_name, data.default_room_type);
bldg = data.building;

}
}
//Call for getting wings according to building
if (input && input.action == "getWings") {
data.wings = loc.getWings(input.building);
}
//Call for getting floors according to building,wing
if (input && input.action == "getFloors") {
data.floors = loc.getFloors(input.building, input.wing, data.default_room_type);

}
//Call for getting floors according to building
if (input && input.action == "getFloorsNoWings") {
data.wfloors = loc.getFloors(input.building, "", data.default_room_type);

}
//cahnge location by open on behalf
if (input && input.action == "changeLocationByUser") {
data.myLocation = loc.getUserLocation(input.caller);
data.location = data.myLocation.location;

data.building.value = data.myLocation.my_building_id;
data.wing.value = data.myLocation.my_wing_name;
data.floor.value = data.myLocation.my_floor_id;
data.room.value = data.myLocation.my_room_name;

data.building.displayValue = data.myLocation.my_building_name;
data.wing.displayValue = data.myLocation.my_wing_name;
data.floor.displayValue = data.myLocation.my_floor_name;
data.room.displayValue = data.myLocation.my_room_name;
if (data.myLocation.location == '' || data.myLocation.my_building_name == '' || data.myLocation.my_wing_name == '' || data.myLocation.my_floor_name == '' || data.myLocation.my_room_name == '') {
data.showAdvancedLocation = true;
data.showLocation = false;
}
/* if(data.sysId_advanced_location_view.indexOf(data.catalog_sysId) != -1){
data.showAdvancedLocation = true;
data.showLocation = false;
}*/
}
//Call for getting Roomsetup according to Category
if (input && input.action == "setRoomTypeProperties") {
data.rproperties = loc.getCategoryMappingProperties(input.category);

}
//call for getting Parking lot(room) according to building,floor
if (input && input.action == "getParkingRoom") {
data.ParkingRoom = loc.getParkingRoom(input.building, input.floor);
}

})();



1 REPLY 1

Vishal Birajdar
Giga Sage

Hi @avinashdubey103 ,

 

If my understanding is correct, you have one variable "floor" which refers to Location table

and have another variable Room Type on catalog item.

So, when user selects the e.g., Room type = Dining then Floor variable should show location with room type as Dining.

 

Do you have any 'Room Type'/ 'Type' field on location table which differentiate between locations...??

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates