Need to populate the value in single line text based on checkbox selected in location table

suuriya
Tera Contributor

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.

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

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'
});

 

AnveshKumarM_1-1700532758672.png

 

 

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', "");
		}
    }
}

 

AnveshKumarM_0-1700532740625.png

 

 

AnveshKumarM_2-1700532788997.png

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

 

 

 

Thanks,
Anvesh

View solution in original post

1 REPLY 1

AnveshKumar M
Tera Sage
Tera Sage

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'
});

 

AnveshKumarM_1-1700532758672.png

 

 

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', "");
		}
    }
}

 

AnveshKumarM_0-1700532740625.png

 

 

AnveshKumarM_2-1700532788997.png

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

 

 

 

Thanks,
Anvesh