How to change referenced tables on one reference field based on other dropdown values.

aastha3
Giga Contributor

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.

1 ACCEPTED SOLUTION

Please replace-


var type=current.u_type;



with


var type=current.variables.u_type;



It should work now. Best of luck.


View solution in original post

25 REPLIES 25

Manoj Kumar16
Giga Guru

Sorry Aastha it was my mistake....



We are setting the query in the variable qualifier and returning grpID



please replace return grpID;


with return qualifier;




I can still see configuration item table and its not changing when I am selecting linux or esx.


Am I doing correctly where is the issue I am not able to understand.



Script Include:



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 qualifier;


  }


  else if(type=='linux')


  {


  qualifier="sys_class_name=cmdb_ci_linux_server"; // Put the query for linux server


  return qualifier;


  }


  },


  type: 'TestScript'


};




Javascript code :



javascript:new TestScript().getCIbasedonClass()



kumamano


Manoj Kumar16
Giga Guru

You can put log statement in in script include and check the logs whether type is coming as you are changing the value.



insert-


gs.log('type is : '+type);



after you declared the qualifier variable. check the logs and confirm. what is the name of the script include which you wrote please confirm. Also confirm the field name of the dropdown and the choice values.


Check the logs after changing the values of the dropdown field in the form.


Type is showing undefined in logs



Name of script include is TestScript


Field Name:CI Type (value): vm_type


Field Name:CI Name value: vm_name




Choices for CI Type:


find_real_file.png