Auto populate Country field

Negha1
Tera Contributor

Hi All,

 

I want a script to Auto Populate the country field based on the Requester field.

I tried onchange client script, But Iam getting undefined as  mapping.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (newValue) {
        if (newValue == oldValue) {
            return;
        }
        var strReqestedFor = g_form.getReference('caller_id');

        if (g_form.getValue('u_country_code')=="") {
            g_form.setValue('u_country_code', strReqestedFor.u_country_code);
        }
    }
}
3 REPLIES 3

Adarsh3003
Giga Guru

HI @Negha1 ,

 

Apply OnChange client script ....

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || isTemplate) {
return;
}

var requesterField = g_form.getValue('requested_for');
if (requesterField) {
var countryField = g_form.getValue('country');
if (countryField === '') {
var grUser = new GlideRecord('sys_user');
grUser.get(requesterField);
if (grUser.hasAttribute('country')) {
g_form.setValue('country', grUser.getValue('country'));
}
}
}
}

 

Hope it will work 

 

If this is helpful for you, Please mark Helpful and Correct solution


Thanks & Regards
Adarsh Verma

Negha1
Tera Contributor

Hi @Adarsh3003 

 

Iam getting the error message in the incident after trying your script,

 

Negha1_0-1715249040173.png

GuruP
Tera Contributor

Hi  Negha1,

You can achieve this by using script include and call it into client script.

 

 

 

thanks,