Passing variable value to script includes in a reference qualifier

Evan7
Tera Contributor

Hi All, 

I have a rather complex form that uses a couple of variable sets as well on form variables. What I'm trying to do is pass the value from a variable in variable to the reference qualifier of the second variable set.

To put it in context I'm trying to pass the value of a "platform" e.g. IIS, I H S, Oracle etc.... through to a Multi Row Variable Set that references the CMDB and filters it accordingly so for IIS will only show windows servers.

So in the advanced reference qualifier of the MRVS I have:

javascript: new SSLCertUtils().filterNodesOnPlatform(current.platform);

The script includes looks like:

filterNodesOnPlatform: function (platform){
var query;

switch (platform){
case "web_iis":
query = 'operational_status=1^sys_class_name=cmdb_ci_win_server^EQ';
break;
case "web_ihs":
query = 'operational_status=1^sys_class_name=cmdb_ci_unix_server^EQ';
break;
default:
query = 'operational_status=1;
}
return query;
},

When I output the value of 'platform' in the script above i get 'undefined'. I have tried all sorts of combinations and nothing seems to work.

When i just pass current and output it i get [object GlideRecord] but i can't find anyway to use this to look up the variable value.

Can someone help me out here.

12 REPLIES 12

Same result unfortunately. When I gs.log('Platform Filter: ' + platform); it comes out as undefined.

Even tried just passing current then using the above code and still the same. 

It's got me stumped as to why its not working. The variable is a select box being populated by a choice list, would this make any difference.

The call to the script includes works if i pass the value directly i.e. 'web_iis' so i know the call is working but that kind of defeats the purpose of using the variable. 

 

Evan - My apologies! I missed a syntax error before. We need to convert the value to string when passing it to the script include for use in the switch case. If you use the following, you should have success:

Ref Qualifier:

javascript:new SSLCertUtils().filterNodesOnPlatform(current.variables.platform.toString())

Script include:

(matches your original)

filterNodesOnPlatform: function (platform){
var query;
switch (platform){
case "web_iis":
query = 'operational_status=1^sys_class_name=cmdb_ci_win_server^EQ';
break;
case "web_ihs":
query = 'operational_status=1^sys_class_name=cmdb_ci_unix_server^EQ';
break;
default:
query = 'operational_status=1;
}
return query;
},
-Stephen

Apologies for the delayed reply, unfortunately still the same result. 

I tried passing the variable as per the above and also tried converting after it was passed and still comes out as undefined.

 

dvp
Mega Sage
Mega Sage

In the provided quote you are missing ' in default case

 

Can you try this

filterNodesOnPlatform: function (platform){
var query;

switch (platform){
case "web_iis":
query = 'operational_status=1^sys_class_name=cmdb_ci_win_server^EQ';
break;
case "web_ihs":
query = 'operational_status=1^sys_class_name=cmdb_ci_unix_server^EQ';
break;
default:
query = 'operational_status=1';
}
return query;
},

 

 

Evan7
Tera Contributor

Thanks for replying. Yes I had already picked up on that and fixed it after i pasted it.