Based on state country name should be autopopulated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 06:38 AM
Hi,
I have a field "state" choice field contains multiple choice.
Now country field which is a string field.
Based on state field selected I want country to be autopopulated.
the logic what I want to implement is :
the choices which are there in state are fixed choices.
So I am dividing them like if choices are karnataka, texas
var state = g_form.getValue('u_state');
if(state == "karnataka"){
g_form.setValue('country') == India;}
else if(state == "Texas"){
g_form.setValue('country') == USA;}
but it works only on client side, I want to implement the same on server side as well.
how to achieve

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 08:20 PM
Or without creating any Client Script nor Script Include.
I've set both State and Country fields to be of type Lookup Select Box.
1. State field
2. Country field
Check "Unique values only" field.
Set Reference qualifier
javascript: 'state=' + current.variables.state;
Set Variable attributes
ref_qual_elements=country;state
Execution result

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 11:10 PM
After all these, if still want to use if-else statement,
var LocationUtil = Class.create();
LocationUtil.prototype = {
initialize: function() {},
getCountry: function(state) {
var country;
if (state == "karnataka") {
country = 'India';
} else if (state == "Texas") {
country = 'USA';
}
return country;
},
type: 'LocationUtil'
};
Sample server script
var state = 'Texas';
var country = new LocationUtil().getCountry(state);
gs.info(country);
Result
*** Script: USA