Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to update fields using another table

Dasari Srihari
Tera Contributor

Hi All,

 

I have 2 tables user table & personal data table. Personal email id available in personal data table available. Now i need to update personal email id in user table. In both tables employee id available based employee id i need to update personal email in user table. How we can achieve this..

1 ACCEPTED SOLUTION

Hi @Dasari Srihari,

 

You need to create after insert/update business rule on personal data table. Below shared the sample scripts, modify it accordingly.

 

Sample scripts:

 

var user_record = new GlideRecord('sys_user');
user_record.addQuery('employee_id', current.employee_id_column_name); // current: object for personal data table
user_record.query();
if (user_record.next()) {

user_record.personal_email_id = current.personal_email_id_column_name.toString();
user_record.setWorkflow(false); // disables the other business rules
user_record.autoSysFields(false); // used to disable the update of 'sys' fields (Updated, Created, etc.) for a particular update
user_record.update();

}


 

Please mark as helpful and correct, if I have been able to assist you in any way!
This will be useful for future readers.

 

Thanks,

Sagar Pagar

The world works with ServiceNow

View solution in original post

8 REPLIES 8

Sagar Pagar
Tera Patron

Hi @Dasari Srihari,

 

What you start so far and where you stuck? Do you need background scripts or you need business rule to update personal email id on insertion/ updation of record in personal data table?

 

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Hi @Sagar Pagar 

 

I need BR if personal email update in personal data table. 

Hi @Dasari Srihari,

 

You need to create after insert/update business rule on personal data table. Below shared the sample scripts, modify it accordingly.

 

Sample scripts:

 

var user_record = new GlideRecord('sys_user');
user_record.addQuery('employee_id', current.employee_id_column_name); // current: object for personal data table
user_record.query();
if (user_record.next()) {

user_record.personal_email_id = current.personal_email_id_column_name.toString();
user_record.setWorkflow(false); // disables the other business rules
user_record.autoSysFields(false); // used to disable the update of 'sys' fields (Updated, Created, etc.) for a particular update
user_record.update();

}


 

Please mark as helpful and correct, if I have been able to assist you in any way!
This will be useful for future readers.

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Hi @Sagar Pagar , Thanks for your response. it is working.

 

Same script i need to run for fix script as well for existing record