How can we decide that a given 'before business rule' should be kept as it is or changed to 'after business rule'?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 08:15 PM
Hello All,
According to ACE reports 'Before Business Rules' should not update() or insert() records on other tables. Now I have to decide whether I should keep the 'before business rule' as it is or change it to 'after business rule'. I wanted to know how to decide that.And I have a wierd code, it would be nice if someone could help me with this.
This business rule runs before insert and update and it is made on the table sysauto_db_check.The code is as shown below:
current.script = "var gr1 = new GlideRecord('ha_db_check');gr1.setValue('check_type',current.check_type);gr1.setValue('target_database',current.target_database);gr1.setValue('auto_repair',current.auto_repair); gr1.insert();";
Should this be kept as it is or changed to after business rule?
Regards,
Reeba

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 08:31 PM
Hi Reeba,
You just have to decide when to execute.
Before Rules:
Since they run before they update in database, the values that you place in your current form will be updated. No need of any current.update();
After Rules:
Since they run after the update in database, you have to forcefully update any changes you are making to record. So, you have pplace"
current.update(); here
Your script will run even in onBefore or onAfter case, since you are inserting record into a new table.
Better if you can make it after Business rule, which means you are grabbing the values from an existing record which is already inserted/updated.
var gr1 = new GlideRecord('ha_db_check');
gr1.setValue('check_type',current.check_type);
gr1.setValue('target_database',current.target_database);
gr1.setValue('auto_repair',current.auto_repair);
gr1.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 08:46 PM
Hi Gowrisankar,
This on before business rule was created on the table 'sysauto_db_check' and it is inserting record into the table 'ha_db_check'. I wanted to know whether it is allowed because the ACE report says before business rules should not update or insert records on other tables.
Regards,
Reeba

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 08:54 PM
Yes, it is allowed to insert records into other tables in onbefore business rules.
But, if "'sysauto_db_check'" record creation is aborted/failed, it should not insert record in "'ha_db_check'", but it can insert which should not.
Due to the above reason ACE Reports prefer insert/update on other tables only in onAfter Business Rules.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 11:40 PM
Thankyou Gowrisankar