Dynamic Field Updates Based on IT World Region in Service Catalog

Urvashi Jain
Tera Contributor
Change worldArea variable dynamically based on requested for's IT World Region
 
In some scenarios, you may need to dynamically update a hidden variable based on another field’s value. For example, when the IT World Region changes, you want to set the Application field automatically.
Here’s how you can achieve this:
 
Steps to Implement
1. Create a Variable
 
Add a variable named it_world_region in your catalog item.
Keep it hidden if you don’t want users to modify it directly.
 
2. Client Script – OnLoad
 
Hide the variable and set the initial value based on the region.
 
script:
function onLoad() {
 
g_form.setDisplay('it_world_region', false);
 
    var regionValue = g_form.getValue('it_world_region'); 
    var applicationValue = '';
 
    if (!regionValue) {
        return; 
    }
 
   switch (regionValue) {
        case 'EMEA':
            applicationValue = 'DAUT-IT-EMEA';
            break;
        case 'North America':
        case 'Latin America':
            applicationValue = 'DAUT-IT-AMRS';
            break;
        case 'Asia Pacific':
            applicationValue = 'DAUT-IT-APAC';
            break;
        default:
            applicationValue = '';
    }
 
    g_form.setValue('application', applicationValue);
 
}
 
3. Client Script – OnChange
 
Triggered when the IT World Region changes.
 
script:
variable name: it_world_region
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
 
    var applicationValue = '';
 
    switch (newValue) {
        case 'EMEA':
            applicationValue = 'DAUT-IT-EMEA';
            break;
        case 'North America':
        case 'Latin America':
            applicationValue = 'DAUT-IT-AMRS';
            break;
        case 'Asia Pacific':
            applicationValue = 'DAUT-IT-APAC';
            break;
        default:
            applicationValue = '';
    }
 
    g_form.setValue('application', applicationValue);
}
 
Key Points:
 
Use g_form.setDisplay() to hide variables dynamically.
Use g_form.setValue() to update other fields based on logic.
Always include checks for isLoading and empty values to avoid unnecessary script execution.
2 REPLIES 2

Mohammed8
Giga Sage

@Urvashi Jain 

Thanks for sharing.

Prefix Article/blog topic heading to not mistake it for question.

Also screenshots would have enhanced your article/blog as it looks good use case

 

Regards,

Mohammed Zakir

nayanmule
Tera Guru

@Urvashi Jain  , thanks for sharing this article. I hope it helps the future readers.

Regards,

Nayan