- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2020 11:12 AM
Hi,
I have written the onChange client script on "time_machine_name" variable to add and remove the option from the select box variable.
script:
function onChange(control, oldValue, newValue, isLoading) {
// if (isLoading || newValue == '') {
// return;
// }
var tmName = g_form.getDisplayBox('time_machine_name').value;
var addDB = g_form.getReference('tmName', addOptionInDBType);
function addOptionInDBType(addDB) {
alert('inside function');
if (addDB.type == 'oracle_database')
alert('insideif'+addDB.type);
g_form.addOption('databaseType', 'oracle_database_clone', 'Oracle');
g_form.removeOption('databaseType', 'saphana_database_clone');
g_form.removeOption('databaseType', 'sqlserver_database_clone');
g_form.removeOption('databaseType', 'postgres_database_clone');
g_form.removeOption('databaseType', 'mysql_database_clone');
g_form.removeOption('databaseType', 'mariadb_database_clone');
}
}
Could you please help me where i am doing wrong?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2020 02:37 AM
Hi Anu,
Is time_machine_name a reference field?
If so, you need to use below.
var addDB = g_form.getReference('time_machine_name', addOptionInDBType);
instead of
var addDB = g_form.getReference('tmName', addOptionInDBType);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2020 02:43 AM
Hi,
Can you explain what is required exactly?
time_machine_name -> is reference variable; so based on value of type field of this table you want to add and remove the options
It is recommended to use GlideAjax instead of getReference() with callback method
But if you require to use getReference() then below is the updated script
function onChange(control, oldValue, newValue, isLoading) {
var addDB = g_form.getReference('time_machine_name', addOptionInDBType);
function addOptionInDBType(addDB) {
alert('inside function');
if (addDB.type == 'oracle_database')
alert('insideif'+addDB.type);
g_form.addOption('databaseType', 'oracle_database_clone', 'Oracle');
g_form.removeOption('databaseType', 'saphana_database_clone');
g_form.removeOption('databaseType', 'sqlserver_database_clone');
g_form.removeOption('databaseType', 'postgres_database_clone');
g_form.removeOption('databaseType', 'mysql_database_clone');
g_form.removeOption('databaseType', 'mariadb_database_clone');
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader