Can't get checkbox value to be recognized in script include

Neil Wallace
Tera Contributor

Really stuck on an issue and could value some help.

I want the reference qualifier query for the company field to depend on whether pharmacy is checked below: 

Have created a reference qualifier as follows:

find_real_file.png

Passing current into the script include. While it recognizes values already saved to database eg. current state. It doesnt recognize values not saved eg. checkbox u_pharmacy.

Completely stumped. And any help much appreciated.

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

GetGPsPharmacySelfRegistration: function(ph) {
var gr = new GlideRecord('core_company');
gr.addQuery('active', 'true');
gr.addQuery('customer', 'true');
gs.log('outside');
gs.log('current state' +ph.state);
gs.log('current u_pharmacy' +ph.u_pharmacy);
gs.log('current name' +ph.first_name);
gs.log('check' + current.getDisplayValue('u_pharmacy'));
if (ph.u_pharmacy){
gs.log('inside');
gr.addQuery('u_pharmacy', 'true');

}
gr.query();

var companies='';
while (gr.next()) {
companies += ',' + gr.sys_id;
}

return 'sys_idIN' + companies;
},

 

 

 

 

find_real_file.png

24 REPLIES 24

Community Alums
Not applicable

Do you get anything from printing it ? Also, you initiate this from the client side ?

Neil Wallace
Tera Contributor

Thanks Joro, Below is script include. Log gives false always for checkbox regardless of whether it is ticked or not  - so it is at least passed in successfully to script include. state is recognized as 'pending'

By client side-> its called when you select the company dropdown field.

Ive heard some possibilities that it might be done using an on change event on the checkbox itself to reset the reference qualifier but I cant think how to do that. The consensus seems to be that what I am doing is the right direction but I cant get it to work. 

find_real_file.png

 

find_real_file.png

Community Alums
Not applicable

so you got it !

Add this here if (ph.u_pharmacy){ - so it's like this :

if (!!ph.u_pharmacy){

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

did you try to send the actual field value rather than sending just the current object

Also ensure function name is different that script include name

ref qualifier:

javascript: new global.GetGPsPharmacySelfRegistration().GetGPsPharmacySelfRegistration1(current.u_pharmacy)

 

Script Include:

GetGPsPharmacySelfRegistration1: function(ph) {
		var gr = new GlideRecord('core_company');
		gr.addQuery('active', 'true');
		gr.addQuery('customer', 'true');
		if (ph.toString() == 'true'){
			gs.log('inside');
			gr.addQuery('u_pharmacy', 'true');
		}
		gr.query();
		var companies = '';
		while (gr.next()) {
			companies += ',' + gr.sys_id;
		}

		return 'sys_idIN' + companies;
	},

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader