The changes made in X form should reflect on Y form

ark257
Tera Contributor

I have two forms X and Y

Both forms have similar fileds called compact which needs to be filled

If the filed compact is filled in X form it should automatically get updated in Y when they are linked with the common filed value Sec

5 REPLIES 5

palanikumar
Giga Sage

You can create a Business rule on table x that runs on change of compact field. Update the table Y with the new value

 

Thank you,
Palani

ark257
Tera Contributor

Hi @palanikumar I have written the below business rule but it wasn't working

 

(function executeRule(current, previous /*null when async*/) {
// Only run if any of the three fields changed
if (current.compact.changes() || current.description.changes() || current.status.changes()) {

var yRec = new GlideRecord('table_Y'); // replace with actual table name
yRec.addQuery('sec', current.sec); // match common field
yRec.query();

while (yRec.next()) {
var updated = false; // track if anything changed

if (current.compact.changes()) {
yRec.compact = current.compact;
updated = true;
}
if (current.description.changes()) {
yRec.description = current.description;
updated = true;
}
if (current.status.changes()) {
yRec.status = current.status;
updated = true;
}

if (updated) {
yRec.update();
}
}
}
})(current, previous);

Me Being Mustaq
Tera Guru

Hi @ark257 ,

 

Use a Business Rule on one table (say X) that finds the matching record in Y by Sec and copies the compact value across whenever it changes

 

Option 1: One‑way sync (X → Y)

Assumptions:

  • Table X: u_table_x, field: u_compact, key: u_sec

  • Table Y: u_table_y, field: u_compact, key: u_sec

Business Rule on X

  • Table: u_table_x

  • When: after insert and after update

  • Condition: current.u_compact.changes()

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

    if (!current.u_sec)
        return;

    var y = new GlideRecord('u_table_y');
    y.addQuery('u_sec', current.u_sec);
    y.query();
    if (y.next()) {
        y.u_compact = current.u_compact;
        y.update();
    }

})(current, previous);
​

This keeps Y’s compact in sync whenever X’s compact is filled/changed

 

You may find below thread helpful:


If it is helpful, please hit the thumbs button please mark the answer as correct based on the impact!!

Kind Regards,

Shaik Mohammed Mustaq

I got the below error after writing the provided script

 

ark257_0-1765835862548.png