Auto Populate Reference Field based on String Field (email)

WP1
Mega Expert

Hello Everyone,

 

I am looking to populate a reference field (manager) based on a string field (manager_email) on sys_user table. The string field has the user's email address. In order to ensure the manager field has the correct user name, we would like to reference the email to auto populate the manager name. Please advise with a script if possible

1 ACCEPTED SOLUTION

WP1
Mega Expert

I used a "before" business rule  "insert/update" and this worked. Script below

 

(function executeRule(current, previous /*null when async*/) {

 var gr = new GlideRecord('sys_user');
 if (gr.get ('email', current.getValue('u_manager_email')));
 current.manager=gr.getUniqueValue();

})(current, previous);

View solution in original post

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

Is the manager reference a field on a table, or variable on a Catalog Item?  Do you want to populate it based on the string field containing the email on the screen as the form loads?  When manager email changes? If you don't want or need to see it populate on the screen, when the record is created or when the manager email is populated or changes, and/or do you want to update all existing table records?

Hello Brad,

 

The two fields are on user table (not variables) and yes, I want the manager reference field to populate based on the string field containing the email address on the form. Only the manager field should update each time the email field is updated or created. All other fields should not be affected (only manager field).

 

Thank you

it seems an onChange client script can work for the 'email' field. that calls a script include that queries the sys_user table based on the email field and then returns the value of the manager field on sys_user. the client script then sets the value of the manager field on your form. is this behavior what you want?

Yes please. That's what I need. Can you help with a script to achieve this?