function onchange(executionContext) {
var formContext = executionContext.getFormContext();
//Gets the custom field value
var customField = formContext.getAttribute("cr8a7_customsinglelinefield").getValue();
//Gets the custom country field reference
var customCountry = formContext.getAttribute("cr8a7_customcountry");
//If the custom field value is null, exit the function.
if(!customField){
return;
}
// Displays the value corresponding to the custom country option set field based on the value of the custom field.
switch(customField){
case "United States":customCountry.setValue(1);break;
case "France":customCountry.setValue(2);break;
case "United Kingdom":customCountry.setValue(3);break;
case "India":customCountry.setValue(4);break;
case "Japan":customCountry.setValue(5);break;
case "Canada":customCountry.setValue(6);break;
//If the mapped country is not included in the Option Set field, a prompt dialog box pops up.
default: alert(`The mapped country: ${customField} is not included in the option set.`)
}
}