Catalog Client Script setValue using a choice Variables text value

jsummers
Kilo Contributor

Trying to use the Text value from a variables choice, chosen on a service catalog form, in a Catalog Client Script and getting nowhere. The idea is to generate a text box string based on the values the user is filling out on the form that they can view and modify, if needed.

Using an onChange Catalog Client Script where 'subject' is the string to be build out and 'category' and 'system' are the variables on the form they are filling out but 'category' is a choice field and we want to be able to use the Text value on that choice field on the setValue string. getDisplayValue is not working.

  var cat = g_form.getValue('category');

  var system = g_form.getValue('system');

  g_form.setValue("subject", 'Outage: ' + cat + ' for ' + system);

1 ACCEPTED SOLUTION

Replace your code with below:




  var cat = g_form.getControl('category');


var catVal = cat.options[cat.selectedIndex].text;


  var system = g_form.getValue('system');


  g_form.setValue("subject", 'Outage: ' + catVal + ' for ' + system);


View solution in original post

9 REPLIES 9

remove below from your code.


var cat = g_form.getDisplayBox('category').value;


jsummers
Kilo Contributor

Ok, so the alert is now giving me the variable text value! But when I try to use that line to set the value, I get [object HTMLSelectElement] in the string (i.e. Outage: [object HTMLSelectElement] for System Name):



  var cat = g_form.getControl('category');


  var system = g_form.getValue('system');


  g_form.setValue("subject", 'Outage: ' + cat + ' for ' + system);


Replace your code with below:




  var cat = g_form.getControl('category');


var catVal = cat.options[cat.selectedIndex].text;


  var system = g_form.getValue('system');


  g_form.setValue("subject", 'Outage: ' + catVal + ' for ' + system);


jsummers
Kilo Contributor

Hardik... you are a rock star! Thanks for your perseverance and patience, you made my day.


mkader
Kilo Guru

@HV - I am trying to do something similar. I have one Select Box Variable with multiple choices. I am trying to access the price of the choices. How can I do that? I can get the value of the variable, but I am unable to access any other fields. I've tried your exact solution but continue to get a javascript error.

var option = g_form.getControl('option');
var optionVal = option.options[option.selectedIndex].text;
var test= confirm("Option: " + optionVal );

Thanks!