Populate select box variable based on the selections from reference and list collector variables

redth
Giga Expert

Hi,

I need to populate a select box variable based on the selections from a reference variable (app_name) and list collector variable (u_database_name1)

I'm using a script include and catalog client script to achieve that functionality. But it's not working. Can you please let me know where to correct the script?

Script Include:

var Getroles = Class.create();
Getroles.prototype = Object.extendsObject(AbstractAjaxProcessor, {
Getbusinessroles: function()
{
var v1 = this.getParameter('sysparm_appid');
var v2 = this.getParameter('sysparm_dbname');
var result = this.newItem("result");
var busrole = new GlideRecord('u_database_role');
busrole.addQuery('u_appid',v1);
busrole.addQuery('u_dbname',v2);
busrole.query();

if(busrole.next()){
return busrole.u_business_role;
}
},
type: 'Getroles'
});

Catalog client script:

Type: Onchange of u_database_name1

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gr = new GlideAjax('Getroles');
gr.addParam('sysparm_name','Getbusinessroles');
gr.addParam('sysparm_appid', g_form.getDisplayBox('app_name').value);
gr.addParam('sysparm_dbname', g_form.getDisplayValue('u_database_name1'));
gr.getXML(getbusrole);
alert('bus1'+g_form.getDisplayBox('u_database_name1').value);
alert('bus11'+g_form.getDisplayBox('app_name').value);

function getbusrole(response){
//g_form.clearOptions('u_business_roles');
g_form.addOption('u_business_roles','','---None---');
g_form.addOption('u_business_roles','','Role not found');

var result = response.responseXML.documentElement.getAttribute("result");
g_form.addOption('u_business_roles', result);

}
}

1 ACCEPTED SOLUTION

That's actually good that they are both reference fields on the custom table, so in the client script

gr.addParam('sysparm_appid', g_form.getValue('app_name').toString());
gr.addParam('sysparm_dbname', g_form.getValue('u_database_name1).toString());

The script include depends on what tables are being referenced.  Is your app_name variable referencing the same table as your u_appid field?  Is your u_database_name1 variable referencing the same table as your u_dbname field?  If yes to both, no changes needed to the script include.  If either or both table fields are different, let me know how the variable sys_id relates to the field table.

View solution in original post

10 REPLIES 10

That's actually good that they are both reference fields on the custom table, so in the client script

gr.addParam('sysparm_appid', g_form.getValue('app_name').toString());
gr.addParam('sysparm_dbname', g_form.getValue('u_database_name1).toString());

The script include depends on what tables are being referenced.  Is your app_name variable referencing the same table as your u_appid field?  Is your u_database_name1 variable referencing the same table as your u_dbname field?  If yes to both, no changes needed to the script include.  If either or both table fields are different, let me know how the variable sys_id relates to the field table.

app_name variable comes from application table and u_appid from custom table A.

u_database_name1 variable comes from oracle instance table and u_dbname from custom table A.

So, I'm trying to pass values from client script instead of sys_ids.

1. Able to pass value for app_name variable

2. Not able to pass value for u_database_name1 variable, so modified the script include as attached below, still it's not working:

var Getroles = Class.create();
Getroles.prototype = Object.extendsObject(AbstractAjaxProcessor, {
Getbusinessroles: function()
{
var answer = [];
var dataname;
var v1 = this.getParameter('sysparm_appid');
var v2 = this.getParameter('sysparm_dbname');
var gr1 = new GlideRecord('cmdb_ci_db_ora_catalog');
gr1.addQuery('sys_id', 'IN', v2);
gr1.query();
if(gr1.next()){
dataname = gr1.name;
}

// var result = this.newItem("result");
var gr = new GlideRecord('u_database_role_repository');
gr.addQuery('u_appid',v1);
gr.addQuery('u_dbname',dataname);
gr.query();
while(gr.next()){
answer.push(gr.u_business_role.value.toString(), gr.u_business_role.label.toString());

}
return answer.toString();
},


type: 'Getroles'
});

Wanted to add one more piece of information:

u_appid from custom table is referenced from application table (app_name comes from application table) and u_dbname from custom table is referenced from oracle instance table (u_database_name1 comes from oracle instance table).

So, can i use sys_ids directly as you mentioned?

 

Yes!  Put your script include back the way it was, and pass sys_ids from the client script since your variables and custom table fields both reference the same tables.  Before the return, add a line to confirm that the script include processed correctly

gs.addInfoMessage(answer.join(','));

redth
Giga Expert

Wanted to add one more piece of information:

u_appid from custom table is referenced from application table (app_name comes from application table) and u_dbname from custom table is referenced from oracle instance table (u_database_name1 comes from oracle instance table).

So, can i use sys_ids directly as you mentioned?