- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 05:46 AM
condition = current.table_name == "incident"
When to run : After Insert/Update
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord("incident");
gr.addQuery("sys_id", current.table_sys_id);
gr.query();
gs.log("===>record exists", gr.next());
while(gr.next()) {
gs.log("===>record glide", gr);
//fi = gr.getElement('isAttachmentUpdated');
gr.setValue('isAttachmentUpdated', 'Updated'); //custom field isAttachmentUpdated
gr.update();
}
// Add your code here
})(current, previous);
Note: I'm able to receive the "record exists" debug as "true" but not able to get the log inside while loop. Please help me understand what is the issue fix as the custom field (isAttachmentUpdated) on incident is also not getting updated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2020 11:00 PM
Hello
If this has answered your question, kindly mark the comment as a correct answer so that the question is moved to solved list.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 07:19 AM
Seems there is some confusion. i don't see any event triggering anywhere.
Can you tell me your complete requirement. Based on that i can suggest you a solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 07:29 AM
Thank you for your quick response!!
Sure, my requirement is i need to fire the update rule on incident when the attachment is updated or deleted. During create it works fine but if i update only attachments, the rule on incident won't fire.
So, I tried to put another business rule on Attachments table (after insert, update). I'm not sure what would be the best way to handle attachments that would fire the rule on incident and wrote the script above, but just wanted to know is there any other way to handle this use-case so that i don't have to update the custom field (isAttachmentUpdated) on Incident every-time ensuring that whenever the attachment is added or deleted, the update rule on incident gets fired with whatever attachment is present on the current record. I hope you understood what I'm trying to achieve here. Please let me know if you need any more clarifications.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 07:44 AM
Hi,
What exactly does the update rule does that is triggered on yoru incident table?
Instead of business rule on incident you can create a script action and put all the code there. Then make that script action listen to th event.
Then trigger the event from the attachment update BR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 07:48 AM
It sends the data of the incident record to an endpoint. Also, is it possible via business rule on incident or not?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 08:02 AM
It is possible. But BRs will run on any one of the DB operations (insert or update or query or Delete) on that table.
In your case, it is best to do with Script Action.
Create an event on your incident table.
Then trigger this event from your attachment BR.
Create a Script Action and select the event which you created. Under script, put your code that you wrote in Br.
This way the Script Action will fire without any update happened on incident table.
Kindly mark the comment as a correct answer and helpful if this helps.