How to autopopulate email address of manager field

swathivaddi
Tera Contributor

Hi,

I have a form on which manager name is a reference type field referencing to User table. (sys_user)

 

There is another field called manager email address which is setup as string field. How to get email address of the selected manager into the email address field?

 

Thank you

1 ACCEPTED SOLUTION

Amit Verma
Kilo Patron
Kilo Patron

Hi @swathivaddi 

 

You can use getReference callback with an On-Change Client Script. Refer below screenshots:

 

AmitVerma_0-1741668023185.png

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    g_form.getReference('manager', getEmail); // Change the manager field name as per your catalog item

function getEmail(manager) { 
    g_form.setValue('email', manager.email); // Change the manager email field name as per your catalog item
}
}

 

Output :

AmitVerma_1-1741668060396.png

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

View solution in original post

5 REPLIES 5

Community Alums
Not applicable

Hi @swathivaddi ,

You can use Reference field in place of a String Field.

 

 

Murthy Ch
Giga Sage

@swathivaddi 

Multiple ways to achieve this. Did you tried anything so far?

Look at this article and select one of the approach to solve your usecase

Thanks,
Murthy

Ankur Bawiskar
Tera Patron
Tera Patron

@swathivaddi 

Few ways

1) why not dot walk that email field from that reference field

OR

2) use onChange , getReference callback and set the value

OR

3) use onChange + GlideAjax

what approach did you try so far and what didn't work?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Amit Verma
Kilo Patron
Kilo Patron

Hi @swathivaddi 

 

You can use getReference callback with an On-Change Client Script. Refer below screenshots:

 

AmitVerma_0-1741668023185.png

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    g_form.getReference('manager', getEmail); // Change the manager field name as per your catalog item

function getEmail(manager) { 
    g_form.setValue('email', manager.email); // Change the manager email field name as per your catalog item
}
}

 

Output :

AmitVerma_1-1741668060396.png

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.