getReference() is not working in scoped app

Ashwini Jadhao
Giga Guru

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?

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

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

 

 

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

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

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