- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 04:57 PM
Hi Community,
I have requirements:
In catalog form there are 2 fields badge access location (reference to cmn_location table) and location type (single line)...on selecting any location in badge access location field its location type needs to be auto populate in location type field.
backend names of fields: badge_access_location, location_type
But this is how location types are there in location record. Like a checkbox
See attachment
For example if i select #100 location in badge access location field then pharma site need to be populate in location type field.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 06:13 PM
Hi @suuriya
For this you can write an onChange catalog client script and use GlideAjax to call a Client Callable ScriptInclude. See the following code.
1. Client Callable Script Include:
var CustomLocationUtils = Class.create();
CustomLocationUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLocationType: function(){
var location = this.getParameter("sysparm_loc");
var locGr = new GlideRecord("cmn_location");
var loc_type = "";
gs.info('MAK: ' + location);
if(locGr.get("sys_id", location)){
var loca_type_fields = {
'u_medical_site' : "Medical Site",
'u_pharma_site' : "Pharma Site",
'u_corp_site' : "Corp Site",
'u_cycle_count' : "Cycle Count",
'u_nuclear_site' : 'Nuclear Site',
'u_client_site' : 'Client Site',
'u_is_international' : 'International',
'u_eit_site' : 'EIT Site'
};
for(key in loca_type_fields){
if(locGr[key] == '1'){
loc_type = loc_type + loca_type_fields[key] + ", ";
}
}
if(loc_type.length > 1){
loc_type = loc_type.substring(0, (loc_type.length -2));
return loc_type;
}
}
return loc_type;
},
type: 'CustomLocationUtils'
});
2. onChange Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("CustomLocationUtils");
ga.addParam("sysparm_name", "getLocationType");
ga.addParam("sysparm_loc", newValue);
ga.getXMLAnswer(populateLocType);
function populateLocType(answer) {
if (answer != '' && answer != null && answer != undefined) {
g_form.setValue('location_type', answer);
}else{
g_form.setValue('location_type', "");
}
}
}
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 06:13 PM
Hi @suuriya
For this you can write an onChange catalog client script and use GlideAjax to call a Client Callable ScriptInclude. See the following code.
1. Client Callable Script Include:
var CustomLocationUtils = Class.create();
CustomLocationUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLocationType: function(){
var location = this.getParameter("sysparm_loc");
var locGr = new GlideRecord("cmn_location");
var loc_type = "";
gs.info('MAK: ' + location);
if(locGr.get("sys_id", location)){
var loca_type_fields = {
'u_medical_site' : "Medical Site",
'u_pharma_site' : "Pharma Site",
'u_corp_site' : "Corp Site",
'u_cycle_count' : "Cycle Count",
'u_nuclear_site' : 'Nuclear Site',
'u_client_site' : 'Client Site',
'u_is_international' : 'International',
'u_eit_site' : 'EIT Site'
};
for(key in loca_type_fields){
if(locGr[key] == '1'){
loc_type = loc_type + loca_type_fields[key] + ", ";
}
}
if(loc_type.length > 1){
loc_type = loc_type.substring(0, (loc_type.length -2));
return loc_type;
}
}
return loc_type;
},
type: 'CustomLocationUtils'
});
2. onChange Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("CustomLocationUtils");
ga.addParam("sysparm_name", "getLocationType");
ga.addParam("sysparm_loc", newValue);
ga.getXMLAnswer(populateLocType);
function populateLocType(answer) {
if (answer != '' && answer != null && answer != undefined) {
g_form.setValue('location_type', answer);
}else{
g_form.setValue('location_type', "");
}
}
}
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh