How to link two different tables

Raviteja K
Tera Expert

Hi All

I need to link two tables one is sys_user and one custom table based on few fields from sys_user tables.

When values in the sys_user gets updated same should be reflected in custom table.

How to achieve this, via a business rule?

Thanks in advance

6 REPLIES 6

Karthik Reddy T
Kilo Sage

Hello Ravi Teja,



Use On after BR(update) and condition(as per your requirement).



Use the below sample script:



assume that you have written in the incident table and updating on SLA table(task_sla).



var inc = new GlideRecord('task_sla');


inc.addQuery('task',current.sys_id);


inc.addQuery('type','sla');


inc.query();



while(inc.next())


{


current.u_custom_field = inc.your_tasksla_field;


}


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

Uncle Rob
Kilo Patron

Before we suggest code solutions, we should be sure we understand the data structure.


The fields that change on your custom table... would you describe them as fields that "come from" the User record?   Or are they fields that belong on your custom table, but merely change with some of the User's fields?



Because one option would be to have anything User related that changes as part of the User from, then simply display those fields on your custom table.


Dave Smith1
ServiceNow Employee
ServiceNow Employee

When values in the sys_user gets updated same should be reflected in custom table.


.. then why not use a Reference Field, if the two were related?


  fields in sys_user table are single line text fields. Data is coming from integration where we don't have access to use it.



we are trying to write a code to fetch unique values from a field for example division and populate those fields in the custom table.