Can't get checkbox value to be recognized in script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2022 05:51 AM
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:
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;
},
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2022 06:07 AM
Do you get anything from printing it ? Also, you initiate this from the client side ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2022 06:15 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2022 07:23 AM
so you got it !
Add this here if (ph.u_pharmacy){ - so it's like this :
if (!!ph.u_pharmacy){
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2022 06:22 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader