How can I auto populate email field, when user field filled.

ND7
Kilo Sage

Dear Expert,

How can I proceed with this requirement? Once the user field name is entered, the email field should automatically populate. Please help Thank you so much. Appreciate your help. 

find_real_file.png

2 ACCEPTED SOLUTIONS

did you try putting alerts ?

make sure your back end names of variables are correct  

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
 
    var user = g_form.getReference('name', userDetails);
    
    function userDetails(user) {
alert(user.email);
        g_form.setValue('email', user.email);
    }
}

View solution in original post

Thank you Ankur, I will try this Catalog lookup for sure. BEST

 

View solution in original post

20 REPLIES 20

Hello, assuming you are doing this on a table, using a business rule to do this would be very simple. For your table that your two fields live on, you can create a business rule to set the value of email when a user is picked in your reference field.

Example:

find_real_file.png

find_real_file.png

find_real_file.png

Let me know if you're trying to do this on a catalog item through the service portal instead and I can help with that too.

var user = g_form.getReference('field_name', function(user))
{
g_form.setValue('field_name', user.email.toString())
});

 

Mohith Devatte
Tera Sage
Tera Sage

Hello,

can you share the script with which you tried to auto populate ?

ND7
Kilo Sage

find_real_file.png

on the form, I would like to type Name and email to be filled in automatically. 

find_real_file.png

but onChange did not work.

find_real_file.png

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

    //Type appropriate comment here, and begin script below
    var user = g_form.getreference('name', function(user) {// map the correct field
        g_form.setValue('email', user.email.toString());// map the correct field
    });

 

 

please help 😞 
}

Hello, change the highlighted 'variable name' in your final picture to the 'name' field. Make sure you set the 'UI Type' to 'All' as well, just in case.

Then change your script to look like this and it should work:
find_real_file.png