- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2023 11:08 PM
I have a requirement where I have to write an onchange script on State variable the state variable holds almost 50 choices and There is an another field called City it has 4 choice on selecting on of the choice in city the state field should show only 2 options and on selecting any of the other options from the Variable 'City' The sate field should show all the other 50 options.I have written a script for first scenario i m struck in the else condition
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2023 01:43 AM
Hi @Trupti Krishnam ,
You can define an array for the default of State Codes right inside your client script. (Or put the array into the system property).
Just loop through the array and add them into the Else statement.
Sample below.
g_form.clearOptions('state');
g_form.clearValue('state');
var arrStates = ['VN','GA','FR','HR','DK','AE','AM','PK','TW','MR','BW','CF','MW','PR','KY','FK','RW','FM','PM','BR','SX','TV','PA','NU','NC','PE','GT','AU','BS','MK','SK','DZ','DO','MC','IT','IS','BY','GE','KG','SN','SZ','GQ','RE','CV','MY','SA','TH','IN'];
var length = arrStates.length;
for (var i in arrStates){
g_form.addOption('state', '', '-- None --');
g_form.addOption('state', arrStates[i], arrStates[i]);
}
In the other hand, you can leverage the Decision Builder to build a lookup.
You can define a mapping between State and City, then retrieve the data using this API below.
DecisionTableAPI
Sample:
Or consider to create your own data lookup table. (which extends the Data Lookup Matcher Rules table)
Samples: Priority Data Lookup [dl_u_priority], Assignment Data Lookup [dl_u_assignment], etc..
Let me know if it works for you.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2023 11:25 PM
In else condition you need to add all the 50 choices again because you are clearing all the options in if conditon and I don't think there is no easy/other way to achieve this scenario. Let me know if you find something else.
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2023 01:43 AM
Hi @Trupti Krishnam ,
You can define an array for the default of State Codes right inside your client script. (Or put the array into the system property).
Just loop through the array and add them into the Else statement.
Sample below.
g_form.clearOptions('state');
g_form.clearValue('state');
var arrStates = ['VN','GA','FR','HR','DK','AE','AM','PK','TW','MR','BW','CF','MW','PR','KY','FK','RW','FM','PM','BR','SX','TV','PA','NU','NC','PE','GT','AU','BS','MK','SK','DZ','DO','MC','IT','IS','BY','GE','KG','SN','SZ','GQ','RE','CV','MY','SA','TH','IN'];
var length = arrStates.length;
for (var i in arrStates){
g_form.addOption('state', '', '-- None --');
g_form.addOption('state', arrStates[i], arrStates[i]);
}
In the other hand, you can leverage the Decision Builder to build a lookup.
You can define a mapping between State and City, then retrieve the data using this API below.
DecisionTableAPI
Sample:
Or consider to create your own data lookup table. (which extends the Data Lookup Matcher Rules table)
Samples: Priority Data Lookup [dl_u_priority], Assignment Data Lookup [dl_u_assignment], etc..
Let me know if it works for you.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2023 03:58 AM
Thank you