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

Alikutty A
Tera Sage

Hi Sam,



Please add this line in your script include



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


    var id = new ArrayUtil().unique(sysid);  
    return 'sys_idIN'+id.join(',');
},


type: 'company_user'


});



Thank You


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


Hi Alikutty,



I've made the above changes, but it is still showing all the results for the environment rather than filtering them by the answer from the u_brands variable?



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



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());
    }
    var id = new ArrayUtil().unique(sysid);
    return 'sys_idIN'+id.join(',');
},


type: 'company_user'


});


I have misunderstood the requirement, Have you tried logging to see if you are receiving a proper sys_id of brand in your script include?



The environment variable should be a Reference field for you to pass SYS_ID's into it, Can you change its Type and try this code once?



getEnv : function(u_brands){


var sysid = [];


var brand = u_brands;


gs.log(u_brands, "Brand");
var env = new GlideRecord('cmdb_ci_environment');   //There was no gap in here after new
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,



Thanks for the above, this seems to work, however if no answer is selected to the u_brands, the u_envi gets the first record that has the company field blank.



What do I need to amend so if u_brands is not answered then u_envi returns no results?



Also if a company has more than 1 environment it is only showing the last record, I need it to give the option to select each one - see below, selected brand of Boxeo, would expect to see the option of 1 Answer Network Live (Classic) and Ageas Kwikfit Live (SELF HOST)   but only see the Ageas one.



find_real_file.png


find_real_file.png




Thanks for your help.