Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

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

Pranav Bhagat
Kilo Sage

getReference won't work in scoped app.you can use script include to get the details.

 

Example

Script Include

var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {
   helloWorld:function() { return "Hello " + this.getParameter('sysparm_user_name') + "!"; } ,
   _privateFunction: function() { // this function is not client callable     
    }
 });




Client Script

var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name', 'helloWorld');
ga.addParam('sysparm_user_name', "Bob");
ga.getXML(HelloWorldParse);
 
function HelloWorldParse(response) {
  var answer = response.responseXML.documentElement.getAttribute("answer");
  alert(answer); }

Regards

Pranav

Akshay H Mulky
Kilo Guru

Hi, 
Can you try changing:

var tmName = g_form.getDisplayBox('time_machine_name').value;
var addDB = g_form.getReference('tmName', addOptionInDBType);

to

var addDB = g_form.getReference('time_machine_name', addOptionInDBType);

Ashwini Jadhao
Giga Guru

Could you please help me to do this.

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