- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 08:45 AM
I extended the User (sys_user) table and added some attachment related columns (to allow for download/deletion via the portal). I created a Business Rule to clear these fields when an attachment is deleted. This works fine when only one attachment is deleted. However if you delete multiple via "Manage Attachments", the business rule runs only once and only one of the attachments related columns are cleared.
Any ideas on what I need to do to catch each deletion?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2017 12:40 PM
Hi Bryan,
Please use few code in your addQuery below.
gr.addQuery('table_sys_id', current.table_sys_id);
You are using if condition to check if sys_id matches and then update the record, that means you will be taking care only one record since var file_sys_id = current.sys_id.toString() will give you sys_id of current record. So, i think if you want to delete all the record based upon the table_sys_id then while loop should work without if/else condition in that.
In your else if condition you are using gr.gr.<variable name>. two times gr is not correct.
In file_sys_id == gr.resume_sys_id, is resume_sys_id a reference field which gives sys_id?
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2017 01:46 AM
HI Bryan,
Two things here,
1. You can first query the sys_attachment table and see if there are no records for the same ticket. This could also work for single as well as multiple attachments..
So,if you do something like
var att=....
..
if(!att.hasNext()){
main code
}
2. Avoid using .update() functions in your BR, specially for After and Before types.. Simply commenting them would do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2017 12:10 PM
Sharique,
I am afraid I am not following you. I read that you should not update the current object (i.e. sys_attachment in this case). However, I thought it is okay to update related objects (the extended sys_user record).
Avoid using current.update() in a business rule script. The update() method triggers business rules to run on the same table for insert and update operations, leading to a business rule calling itself over and over. Changes made in before business rules are automatically saved when all before business rules are complete, and afterbusiness rules are best used for updating related, not current, objects. When a recursive business rule is detected, the system stops it and logs the error in the system log. However, current.update() causes system performance issues and is never necessary.
I do not know how I would accomplish my goal without using update().

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2017 12:40 PM
Hi Bryan,
Please use few code in your addQuery below.
gr.addQuery('table_sys_id', current.table_sys_id);
You are using if condition to check if sys_id matches and then update the record, that means you will be taking care only one record since var file_sys_id = current.sys_id.toString() will give you sys_id of current record. So, i think if you want to delete all the record based upon the table_sys_id then while loop should work without if/else condition in that.
In your else if condition you are using gr.gr.<variable name>. two times gr is not correct.
In file_sys_id == gr.resume_sys_id, is resume_sys_id a reference field which gives sys_id?
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2017 12:48 PM