- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2023 04:01 AM
I have a business rule on the 'alm_asset' table that after an update of a record, updates all other records that have the same Serial Number.
After updating the icon that indicates a change on a field appears but the value is not updated:
 The business rule script is:
(function executeRule(current, previous /*null when async*/ ) {
////////////////////// Query the 'alm_asset' table for records with the same serial number///////////////
var serialNumber = current.serial_number;
var assetGr = new GlideRecord('alm_asset');
assetGr.addQuery('serial_number', serialNumber);
assetGr.query();
///////////////////////Get all fields///////////////////////////////////////////////////////////////////
var arr_fields = [];
var fields = new GlideRecord('sys_dictionary');
fields.addQuery('name', 'alm_asset');
fields.query();
while (fields.next()) {
arr_fields.push(fields.element.toString());
}
///////////////////// Loop through matching records and update them/////////////////////////////////////////
while (assetGr.next()) {
if (assetGr.sys_id != current.sys_id) {
// Update the fields on related records
for (i = 0; i < arr_fields.length; i++) {
assetGr.setValue(arr_fields[i], current.getValue(arr_fields[i]));
}
assetGr.update();
}
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 03:35 AM
The problem was that my script was trying to change the sys_id.
The working script is:
(function executeRule(current, previous /*null when async*/ ) {
////////////////////// Query the 'alm_asset' table for records with the same serial number///////////////
var serialNumber = current.serial_number;
var assetGr = new GlideRecord('alm_asset');
assetGr.addQuery('serial_number', serialNumber);
assetGr.addQuery('sys_id', '!=', current.sys_id);
assetGr.query();
///////////////////////Get all fields///////////////////////////////////////////////////////////////////
var arr_fields = [];
var fields = new GlideRecord('sys_dictionary');
fields.addQuery('name', 'alm_asset');
fields.query();
while (fields.next()) {
arr_fields.push(fields.element.toString());
}
///////////////////// Loop through matching records and update them///////////////////////
while (assetGr.next()) {
for (i = 0; i < arr_fields.length; i++) {
if(arr_fields[i] != 'sys_id'){
assetGr.setValue(arr_fields[i], current[arr_fields[i]]);
}
}
assetGr.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2023 06:08 AM
Hi @Community Alums.
There are 2 of them with Operation of report_view

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2023 06:11 AM
okay, please check the ACL rules, if they have proper permissions or else you can't view those fields.
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2023 06:14 AM
Looked on it. Unfortunately the issue does not lie there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 03:35 AM
The problem was that my script was trying to change the sys_id.
The working script is:
(function executeRule(current, previous /*null when async*/ ) {
////////////////////// Query the 'alm_asset' table for records with the same serial number///////////////
var serialNumber = current.serial_number;
var assetGr = new GlideRecord('alm_asset');
assetGr.addQuery('serial_number', serialNumber);
assetGr.addQuery('sys_id', '!=', current.sys_id);
assetGr.query();
///////////////////////Get all fields///////////////////////////////////////////////////////////////////
var arr_fields = [];
var fields = new GlideRecord('sys_dictionary');
fields.addQuery('name', 'alm_asset');
fields.query();
while (fields.next()) {
arr_fields.push(fields.element.toString());
}
///////////////////// Loop through matching records and update them///////////////////////
while (assetGr.next()) {
for (i = 0; i < arr_fields.length; i++) {
if(arr_fields[i] != 'sys_id'){
assetGr.setValue(arr_fields[i], current[arr_fields[i]]);
}
}
assetGr.update();
}
})(current, previous);