Filtering a Variable from another Variable answer

Sam Ogden
Tera Guru

Hi All,

I have a record producer that will be used on our Service Portal.

This has the variable u_brands (Are any of your brands affected?).   I need the answer from this to filter the choices available in the u_envi variable (Which environment is affected, if known?).

u_brands is a reference of the core_company table and u_envi is a lookup select box of the cmdb_ci_environment table.

I've tried to create a script includes to use in the reference qualifier of the u_envi variable, however it is just showing every environment rather than filtering on the answer from u_brands.

As can see from the screenshots I am only expecting to see the 1Answer Network Live (Classic) environment with the brand boxeo selected.

Any help is greatly appreciated.

find_real_file.png

find_real_file.png

find_real_file.png

Reference qual:

javascript: new company_user().getEnv(current.variables.u_brands);

Script includes:

getEnv : function(u_brands){
var brand = u_brands;
var env = newGlideRecord('cmdb_ci_environment');
env.addQuery('company', brand);
env.query();
while(env.next()){
  sysid.push(env.name.toString());
    }
    return 'sys_idIN'+sysid.join(',');
},

type: 'company_user'

});

1 ACCEPTED SOLUTION

So you have only 2 records, You need to check the System Logs -> All module to view the log. Please try this out once



getEnv : function(u_brands){


var sysid = '';


var brand = u_brands;


if(brand == ''){


return 'sys_idIN';


}else{


var env = new GlideRecord('cmdb_ci_environment');


env.addQuery('company', brand);


env.query();
while(env.next()){
    sysid += "," + env.sys_id;


}


return 'sys_idIN'+sysid.substring(1);


}



},


type: 'company_user'


});



Thank You


Please Hit Like, Helpful or Correct depending on the impact of response


View solution in original post

12 REPLIES 12

Try this one for empty brands



getEnv : function(u_brands){


var sysid = [];


var brand = u_brands;


if(brand == ''){


return 'sys_idIN';


}else{


var env = new GlideRecord('cmdb_ci_environment');


env.addQuery('company', brand);


env.query();
while(env.next()){
    sysid.push(env.sys_id);


}


return 'sys_idIN'+sysid.join(',');


}



},


type: 'company_user'


});



Thank You


Please Hit Like, Helpful or Correct depending on the impact of response


Hi Alikutty,



That's great for the empty brands,


Just need it to return all the environments for the company if the company has more that 1?


It should have returned all of the brands, Can you please apply the company filter on the cmdb_ci_environment table and see if it returns all data? Also please log the sys_id and paste the value here



getEnv : function(u_brands){


var sysid = [];


var brand = u_brands;


if(brand == ''){


return 'sys_idIN';


}else{


var env = new GlideRecord('cmdb_ci_environment');


env.addQuery('company', brand);


env.query();
while(env.next()){
    sysid.push(env.sys_id);


}


gs.log(sysid.join(','));


return 'sys_idIN'+sysid.join(',');


}



},


type: 'company_user'


});



Thank You


Please Hit Like, Helpful or Correct depending on the impact of response


Hi Alikutty,



I've ran a filter on cmdb_ci_environment



find_real_file.png


I've added in gs.log(sysid.join(','));



Where do I need to go to see this?


So you have only 2 records, You need to check the System Logs -> All module to view the log. Please try this out once



getEnv : function(u_brands){


var sysid = '';


var brand = u_brands;


if(brand == ''){


return 'sys_idIN';


}else{


var env = new GlideRecord('cmdb_ci_environment');


env.addQuery('company', brand);


env.query();
while(env.next()){
    sysid += "," + env.sys_id;


}


return 'sys_idIN'+sysid.substring(1);


}



},


type: 'company_user'


});



Thank You


Please Hit Like, Helpful or Correct depending on the impact of response