- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2017 11:46 AM
I have a form that, in part, uses four related fields to identify where a piece of hardware is located, and what type it is. I've written a client script that will clear all four fields when one (business_unit) is cleared.
Script Type = onChange
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
g_form.setValue('district', '')
g_form.setValue('area', '')
g_form.setValue('structure_type', '');
}
This works exactly as it's supposed to. Because you can only query one field in a client script, I've written additional scripts on district, area, and structure_type fields. They mirror the original script, only changing the setValue field names. As you can imagine, once I've done that, it's a race to see which script works (or doesn't).
I receive this error if I activate any of the addition scripts:
onChange script error: RangeError: Maximum call stack size exceeded function (){var o=i(m,arguments);return l.apply(n,o)}
Not much of a surprise, as I should be able to find some way to do this in a single script. Therein lies my challenge - I have no idea where to start. Please help?
Thanks,
Debbi
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2017 01:46 PM
I think you might be hitting an infinite loop. Try adding (for each variable you're trying to update in each script):
if(g_form.getValue('business_unit')!=''){
g_form.setValue('business_unit','');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2017 01:35 PM
It looks like your script is missing some semi-colons. Not sure if that's because it's missing in your actual script or just in what you put here.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
g_form.setValue('district', '');
g_form.setValue('area', '');
g_form.setValue('structure_type', '');
}
I would also suggest adding else if(newValue == '')
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
else if(newValue == ''){
g_form.setValue('district', '');
g_form.setValue('area', '');
g_form.setValue('structure_type', '');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2017 01:41 PM
Thanks, Kristen. This script actually works. It's when I add the second script, which uses the same set of four fields, but queries a different one, that it fails.
Script #2, using the "District" field (I added your recommendations to both):
- function onChange(control, oldValue, newValue, isLoading, isTemplate) {
- if (isLoading) {
- return;
- }
- else if(newValue == ''){
- g_form.setValue('business_unit', '');
- g_form.setValue('area', '');
- g_form.setValue('structure_type', '');
- }
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2017 01:46 PM
I think you might be hitting an infinite loop. Try adding (for each variable you're trying to update in each script):
if(g_form.getValue('business_unit')!=''){
g_form.setValue('business_unit','');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2017 01:55 PM
That did the trick, thank you!
Used the same script (with the different fields) for all three, no errors, and works exactly as it should. Thanks for your help!
Final script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
else if(newValue == ''){
if(g_form.getValue('district')!=''){
g_form.setValue('district','');
}
if(g_form.getValue('area')!=''){
g_form.setValue('area','');
}
if(g_form.getValue('structure_type')!=''){
g_form.setValue('structure_type','');
}
}
}