- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2015 04:26 PM
Hey all
I have a catalogue form with a large list of checkboxes.
I'd like to know how to detect which checkbox has been clicked by a requestor so I can apply a style to differentiate it from the checkboxes that are auto-filled.
I've no idea where to start.
Anyone got any ideas?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2015 11:36 PM
Hi Bryce, you were right! Here goes the fix. Add the following at the beginning of your inline defined onclick function (@ line 12)
gel('IO:' + item.sys_id).value = this.checked;if (typeof(variableOnChange) == 'function') variableOnChange('IO:' + item.sys_id);
I'll appreciate if you can mark this post as the correct one or as a helpful one so that others reading this post in the future know that this line is *key* to be added in the inline defined onclick function.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2015 05:28 PM
Hi Bryce,
This sounds like a case for onChange client scripts:
Creating a Catalog Client Script - ServiceNow Wiki
Have you tried those?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2015 05:32 PM
Hi Cory,
Yes I thought about using a client script at first, however as I far as I am aware, each script can only detect change on one specific field, instead of the 50-60 that I have on my form (I know, I know...). I am fairly new to all this, so I may be wrong!
Ideally I'd like to do this in one script rather than an individual script for each checkbox.
Thanks
Bryce
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2015 08:43 PM
Hi Bryce, indeed this is possible. pulling up one or two tricks .
Couple of things that you will need to know of how we can do this:
a) you will need to know the id by which your checkboxes are been named by ServiceNow. Or how to reach to these through the item_option_new table.
b) you will need to have an onLoad script on which you're going to define the onClick event for your checkboxes
Here goes a very simple example using OOB Fuji elements. We're going to make an alert that will display whenever the knowledge checkbox is checked or unchecked on the incident form. Keep in mind this is just an example. You can apply the exact same concept using a catalog client script on your catalog.
For this example you just need to create an onLoad client script the one is going to have a code like the following:
function onLoad() {
gel('ni.incident.knowledge').onclick = function() {
alert('This is checked: ' + this.checked + ' and its value is ' + this.value);
};
}
Notice that here we're defining what the onclick of the ni.incident.knowledge checkbox should be. You can use the exact same concept on an onLoad catalog client script where you iterate through your list of checkboxes defining the onclick function for each.
The script on an onLoad catalog client script will look something like this:
function onLoad() {
var sys_id_of_variable = 'dba29ae84fc20200fbb73fb28110c721';
gel('ni.IO:' + sys_id_of_variable).onclick = function() {
alert('This is checked: ' + this.checked + ' and its value is ' + this.value);
};
}
Notice that each variable has an id. You can identify and iterate through your checkbox variables by doing a GlideRecord query against the item_option_new table so that you can grab the sys_id of each variable associated to your catalog item and append the 'ni.IO:' at the start of it.
I hope this is helpful!
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2015 08:49 PM