- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2022 01:19 PM
I'm having a difficult time getting this script to do what I want it to do. It should be looking at the Division (newValue) and then depending on that, clear all options in location and populate with a specific set for each Division.
If I use the script as written below, whenever the form loads, it changes the location field to whatever the first option in the list is.
If I change the first if in the function to (isLoading || newValue === ' '), it then works as intended and doesn't change the location field itself, but it also shows every location for every division instead of just the appropriate locations. I'm not sure what I'm missing here.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue === '') {
return;
}
if(newValue=='Charleston')
{
g_form.clearOptions('u_hr_location', 'Location');
g_form.addOption('u_hr_location','Charleston','Charleston');
g_form.addOption('u_hr_location','Charleston MCP','Charleston MCP');
}
else if(newValue=='Florence')
{
g_form.clearOptions('u_hr_location', 'Location');
g_form.addOption('u_hr_location','Florence','Florence');
g_form.addOption('u_hr_location','Florence MCP','Florence MCP');
g_form.addOption('u_hr_location','Marion','Marion');
g_form.addOption('u_hr_location','Marion MCP','Marion MCP');
}
else if(newValue=='Lancaster')
{
g_form.clearOptions('u_hr_location', 'Location');
g_form.addOption('u_hr_location','Chester','Chester');
g_form.addOption('u_hr_location','Lancaster','Lancaster');
g_form.addOption('u_hr_location','Lancaster MCP','Lancaster MCP');
}
else if(newValue=='Midlands')
{
g_form.clearOptions('u_hr_location', 'Location');
g_form.addOption('u_hr_location','Columbia','Columbia');
g_form.addOption('u_hr_location','Kershaw','Kershaw');
g_form.addOption('u_hr_location','Midlands MCP','Midlands MCP');
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2022 02:02 PM
You will need an onLoad script to perform essentially the same functionality, as onChange will only fire when the value changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2022 02:02 PM
You will need an onLoad script to perform essentially the same functionality, as onChange will only fire when the value changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2022 02:07 PM
I only want it to change when the value changes. But that's the problem, right now...it's changing onLoad even without the onLoad call...that's what's confusing me.
If Division is Charleston, and Department is Charleston MCP. When the form loads, it changes the Department to Charleston (which is the first option in the list). Same for the other Divisions. The expected result is for nothing to change onLoad; and only update the department list if the division changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2022 02:23 PM
Yes, but the reason that it's showing ALL values on load, is because it isn't going through the process of clearing out and creating the new valid choices.
If you add an onLoad script (in addition to the onChange), then it will go through that process and load only the relevant options to the choice already selected.
So your onLoad would grab the value in the field, clear the location options, and add the relevant options.
That said, shreyakaushik's response is a better method if you can use that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2022 02:27 PM
Yeah, please see if that solves your purpose else I will try to help you out with your script itself.