- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2017 10:18 AM
Hi Experts!
I am trying to sync two fields in different tables.
When a Company is selected in the table ['u_contrato_esquema_de_servicio'], in the other form [core_company], the system has to sync with the "u_compania" field.
I try to do this with a business rule when the u_compania changes
var getCompa = current.u_compania.getRefRecord();
getCompa.u_compania = current.u_contrato;
getCompa.update();
and other business rule that I tried is:
var prj = new GlideRecord('core_company');
prj.addQuery('sys_id',current.u_compania);
prj.query();
var rp = new GlideRecord('u_contrato_esquema_de_servicio');
rp.addQuery('u_compania',current.u_compania);
rp.query();
if(prj.next()) {
prj.u_contrato = rp.u_compania;
}
but any of those scripts worked,
Any idea what do I am missing?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2017 10:42 AM
Hi Christopher,
I'm not really sure whats wrong with the script since we don't know what tables they are running on..will need more info. Also, you don't need to query both the tables if you are writing a business rule since you already have access to one using 'current' object.
However here is the script that I think should work: (Untested code)
After Update Business Rule on Table 'u_contrato_esquema_de_servicio':
//After updating Contrato table with the new Company field value, this script queries the Company table for the record referred here and updates the contrato field with current sys_id (since it is a reference field)
var gr = new GlideRecord('core_company');
gr.addQuery('sys_id', current.u_compania);
gr.query();
while(gr.next()){
gr.u_contrato = current.sys_id;
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2017 10:42 AM
Hi Christopher,
I'm not really sure whats wrong with the script since we don't know what tables they are running on..will need more info. Also, you don't need to query both the tables if you are writing a business rule since you already have access to one using 'current' object.
However here is the script that I think should work: (Untested code)
After Update Business Rule on Table 'u_contrato_esquema_de_servicio':
//After updating Contrato table with the new Company field value, this script queries the Company table for the record referred here and updates the contrato field with current sys_id (since it is a reference field)
var gr = new GlideRecord('core_company');
gr.addQuery('sys_id', current.u_compania);
gr.query();
while(gr.next()){
gr.u_contrato = current.sys_id;
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2017 10:50 AM
Thank you so much veena.kvkk88 It works.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2017 10:49 AM
Hey Juarez,
Write a after business rule on core_company when the u_compania changes
and use the following script
var rp = new GlideRecord('u_contrato_esquema_de_servicio');
rp.addQuery('sys_id',current.u_contrato);
rp.query();while(rp.next()) {
rp.u_compania = current.sys_id;
rp.update();
}