The CreatorCon Call for Content is officially open! Get started here.

I have to write a on Change script on a Variable state file to show 2 choices out of 50 choice

Trupti Krishnam
Tera Contributor

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 

 if (newValue == 'house_hold') {
        g_form.clearOptions('state');
        g_form.addOption('state', '', '-- None --');
        g_form.addOption('state', 'UT', 'UT');
        g_form.addOption('state', 'CO', 'CO');
    } 
Thank you

 

1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

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:

Screenshot 2023-10-23 at 15.38.58.png

 

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

 

View solution in original post

3 REPLIES 3

Murthy Ch
Giga Sage

Hi @Trupti Krishnam 

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.

Thanks,
Murthy

Tai Vu
Kilo Patron
Kilo Patron

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:

Screenshot 2023-10-23 at 15.38.58.png

 

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

 

Trupti Krishnam
Tera Contributor

Thank you