- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 09:49 AM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 01:09 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 10:29 AM
You can try either of these:
1. If your choice field is a reference then: var val = g_form.getReference('category').name;
2. If it not a reference field: g_form.getDisplayBox('category').value
Regards,
Hardik Vora
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 11:28 AM
So the variable is just a Select Box type, with the Question Choices created right there on the variable.
Tried both, although it seemed like the second was the answer, but I'm not getting any results after this on the client script:
var cat = g_form.getDisplayBox('category').value;
var system = g_form.getValue('system');
g_form.setValue("subject", 'Outage: ' + cat + ' for ' + system);
Nothing is happening to the "subject" field, it is blank now when before the 'cat' value was just showing blank but the "subject" field was being populated with everything else.
Tried adding an alert but the alert does not even pop-up when ran:
var cat = g_form.getDisplayBox('category').value;
alert(cat);
var system = g_form.getValue('system');
g_form.setValue("subject", 'Outage: ' + cat + ' for ' + system);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 12:03 PM
This should work:
var cnt = g_form.getControl('category');
alert(cnt.options[cnt.selectedIndex].text);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 12:45 PM
Not getting the alert either nor is the setValue working.
var cat = g_form.getDisplayBox('category').value;
var cnt = g_form.getControl('category');
alert(cnt.options[cnt.selectedIndex].text);
var system = g_form.getValue('system');
g_form.setValue("subject", 'Outage: ' + cat + ' for ' + system);