Passing variable value to script includes in a reference qualifier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2019 07:21 PM
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.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2019 04:40 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2019 08:08 AM
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;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2019 02:16 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2019 06:22 AM
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;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2019 05:29 PM
Thanks for replying. Yes I had already picked up on that and fixed it after i pasted it.