- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2016 04:22 AM
I have a requirement where I have three variables in service catalog
1. CI Type(select box) -> VM , Linux , ESX, JBOSS
2. CI Name (reference field)
3. Sys ID (single line text)
Now I want that whenever the CI type is changing the referenced table in CI Name should change accordingly with their respective tables.
like for vm ->cmdb_ci_vm similarly for others as well.
My end result is to fetch selected ci name's sys id .
For changing reference field script include and onchange client script will be required .
for sysid fetch also onchange or onsubmit script will be required . Not sure about this
Please help me with the correct code for my requirement .
Let me know if you need any further information.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2016 02:13 AM
Please replace-
var type=current.u_type;
with
var type=current.variables.u_type;
It should work now. Best of luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2016 04:43 AM
You can put the Reference table as cmdb_ci (the parent table) and then change the Reference qualifier dynamically using advance reference qualifier.
You need to call a script include from the advance reference qualifier based on the class selected(ESX, VM etc).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2016 05:57 AM
Can you provide me the script include code .
also I want the sys id to be fetched of the selected ci record name in CI Name .
Also as the CI name will change the referenced table should also change it will require onchange client script if I am not wrong.
Please provide script for changing reference table in reference field and for fetching sys id of CI record .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2016 06:21 AM
Step 1- go to cmdb_ci table and collect the queries - By setting the filter as class is ESX Server and copying the query as shown in the image below
Step 2-
Write a script include -
var TestScript = Class.create();
TestScript.prototype = {
initialize: function() {
},
getCIbasedonClass : function()
{
var type=current.ci_type;// select box fields(Please replace ci_type with the name of selectbox
var qualifier=''
if(type=='ESX')//value of the choice field eg.ESX
{
qualifier="sys_class_name=cmdb_ci_esx_server";//Query which we copied
return grpID;
}
else if(type=='AIX')
{
qualifier="Query copied from cmdb_ci table for AIX"; // Put the query which you have copied for AIX server and continue the same process for all the options
return grpID;
}
},
type: 'TestScript'
};
Step 3:
Set the reference qualifier and call the Script include and function
You can also use Switch case in the script include that would be better. I have written it in if else which takes more time to execute as the script iterates all the conditions.
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2016 10:33 AM
Its not working .
I tried with your code :
var TestScript = Class.create();
TestScript.prototype = {
initialize: function() {
},
getCIbasedonClass : function()
{
var type=current.vm_type;// select box fields(Please replace ci_type with the name of selectbox
var qualifier='';
if(type=='esx')//value of the choice field eg.ESX
{
qualifier="sys_class_name=cmdb_ci_esx_server";//Query which we copied
return grpID;
}
else if(type=='linux')
{
qualifier="sys_class_name=cmdb_ci_linux_server"; // Put the query for linux server
return grpID;
}
},
type: 'TestScript'
};
Catalog variables:
Even if I change CI Type as ESX and I clicked magnifying icon on CI Name its showing configuration table. cmdb_ci
Please check and let me know what to do.
This is an urgent requirement.
CI Name variable :
Please kumamano help me out with this code and to fetch sys id code.