- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2022 02:57 AM
I have 2 tables -- Chromebook table and computer table. When any user inserts or updates any record in chromebook table, the same should also get inserted or updated into computer table.
I am writing after BR on Chromebook table as follows -
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('cmdb_ci_computer'); //your Computer table name
gr.addQuery('sys_id', current.u_serial_number); //you can query the records based unique fields.ex: incident number
gr.query();
if (gr.next()) {
//Update records
gr.name = current.u_name; //here updating the values on fields
gr.serial_number = current.u_serial_number;
gr.location = current.u_location;
gr.model_id = current.u_model;
gr.install_status = current.u_status;
gr.owned_by=current.u_user;
gr.short_description = current.u_notes;
gr.update();
} else {
//create new records
gr.initialize();
gr.name = current.u_name; //here updating the values on fields
gr.serial_number = current.u_serial_number;
gr.location = current.u_location;
gr.model_id = current.u_model;
gr.install_status = current.u_status;
gr.owned_by=current.u_user;
gr.short_description = current.u_notes;
gr.insert();
}
}
)(current, previous);
Here the record is getting inserted into computer table, but when any user tries to update the record it is not working
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2022 03:40 AM
Change this line for starters
gr.addQuery('sys_id', current.u_serial_number); //you can query the records based unique fields.ex: incident number
gr.addQuery('serial_number', current.u_serial_number); //you can query the records based unique fields.ex: incident number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2022 03:40 AM
Change this line for starters
gr.addQuery('sys_id', current.u_serial_number); //you can query the records based unique fields.ex: incident number
gr.addQuery('serial_number', current.u_serial_number); //you can query the records based unique fields.ex: incident number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2022 01:17 AM
Hii,
The above BR does not work for inserting new records