Trigger report subscription from change in Custom Table

Lance Keay asked on April 20, 2016 11:44

Is there a way to trigger a report subscription due to a change in a custom table?

eg: We are adding values to a custom table and tracking how many rows there are - I'd like to trigger a report subscription for every 100 rows added to the custom table.

Recent Answers


Brenden Kehren answered on April 20, 2016 14:02

Out of the box, no. I'd start by creating one of two things:

  • Custom event handler which performs that count each time a custom table object is entered. Downside of this is it makes an additional COUNT(*) call for every insert action.
  • Scheduled task which runs every X minutes and does the same thing. The upside of this is it will always run at a given time and is predictable. The downside is you will need to store what the last count was after each count so you have something to compare with.
1 votesVote for this answer Mark as a Correct answer

Lance Keay answered on April 20, 2016 14:21

The sched task is what I was going to do if there isn't an easier way.

I was hoping to leverage the 'condition' field of a report subscription in some magical way.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on April 20, 2016 14:48

Well you could write a macro and the possibly utilize the 'condition' field but I think your best approach (less intensive and invasive) is the scheduled task. Ask yourself these questions:

  • How frequently will these "reports" be read?
  • Is there a need to have the report automatically send at the exact minute EVERY TIME the count reaches 100?
  • What happens when the automation errors out? (doesn't matter it it's global event handler, scheduled task or a macro)
0 votesVote for this answer Mark as a Correct answer

Laura Frese answered on April 20, 2016 19:49

If you arent deleting any of the rows and the ItemID is always in sequence without any breaks you might try using the event handler and checking to see if the ItemID is dividable by 100 without any remainder (mod) then trigger the report. If you need some info on custom table event handler..

[CustomTableInterceptor]
public partial class CMSModuleLoader
{
    public class CustomTableInterceptor : CMSLoaderAttribute
    {
        public override void Init()
        {
             CustomTableItemEvents.Insert.After += CustomTableItem_After_Insert;
        }

        protected void CustomTableItem_After_Insert(object sender, CustomTableItemEventArgs e)
        {
            CustomTableItem customtableitem = (CustomTableItem)e.Item;
            string tablename = customtableitem.ClassName;
            //etc
        }
    }
2 votesVote for this answer Mark as a Correct answer

Lance Keay answered on April 20, 2016 20:13

Thanks Laura - I think I'm going to go with your & Brenden's suggestion of using an Event Handler. I'll need to update another custom table with some values so that I can track the emails sent and avoid duplicate messages.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.