Location Filed is not Updating using Business Rule script
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 07:33 AM
Hi Everyone,
I have created an After Business rule for the sc_req_item table to update the asset’s Install Status and Location. While the Install Status is updating correctly, the Location (which refers to the cmn_location table) is not updating. The Location should update based on the checkbox selected in the item variable.
Please refer to the script below and help me resolve this issue?
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('u_cmdb_ci_workstation');
gr.addQuery('sys_id', 'IN', current.variables.group);
gr.query();
while (gr.next()) {
gr.install_status = '6';
// Check the FR checkbox and update the location
if (gr.get(current.variables.FR == true)) {
gs.log('FR checkbox is checked');
gr.setValue('location', '05d5a53d6f1721005fa8fbf7eb3ee419'); // Location ID for FR
gr.setValue('virtual', true);
} else {
gs.log('FR checkbox is not checked');
}
// Check the US checkbox and update the location
if (gr.get(current.variables.US == true)){
gr.setValue('location', 'another_location_id'); // Replace with the actual Location ID for US
}
gr.update();
}
})(current, previous);
Thanks,
Rajesh
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 08:22 AM
You don't need/want to get the value of the checkbox from the GlideRecord
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('u_cmdb_ci_workstation');
gr.addQuery('sys_id', 'IN', current.variables.group);
gr.query();
while (gr.next()) {
gr.install_status = '6';
// Check the FR checkbox and update the location
if (current.variables.FR == true) { //if this doesn't work, try 'true'
gs.log('FR checkbox is checked');
gr.setValue('location', '05d5a53d6f1721005fa8fbf7eb3ee419'); // Location ID for FR
gr.setValue('virtual', true);
} else {
gs.log('FR checkbox is not checked');
}
// Check the US checkbox and update the location
if (current.variables.US == true)){
gr.setValue('location', 'another_location_id'); // Replace with the actual Location ID for US
}
gr.update();
}
})(current, previous);
If this still isn't working for you, which logs are you seeing?