Email notification to all group members

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
Moh Youba
Veteran Member
Posts: 228
Joined: 2017-03-12 09:31

Email notification to all group members

Post by Moh Youba » 2020-07-31 23:11

Hello

I need to send out an email notification to all group members after a record has been added or updated.
The email title needs to come from a field from a table.
When notification is receive, if user clic on the title, it redirect user to the added record after user login.

Thank for any help

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Email notification to all group members

Post by pfrumkin » 2020-08-02 17:28

Hi,

That sounds a lot like you want to add something in the tablename_after_insert and tablename_after_update hooks. In the hook, you do your select from the table that has your subject. The body of the email would have the hyperlink to the added record.

I added a button on a table dv page to redirect to another page (php file) that does all the work. A trick at that point is that I pass the current record in the querystring to that page. This uses the Helper library from Bizzworxx (AppGiniDetailView) to add the button.

Code: Select all

	var targetRootURL = "hooks/send_email.php?recID=";
	var targetURL = targetRootURL.concat($j( 'input[name=SelectedID]' ).val());  // This adds the current record ID to the querystring
	var dv = new AppGiniDetailView();
	var actionbuttons = dv.actionbuttons;
	var group = actionbuttons.addGroup("Actions");
	group.addLink("Send Tow Request", targetURL, Variation.Primary, "send");
In the target page, I have

Code: Select all

  $recID = $_GET['recID'];  // This reads in the current record ID from the querystring
  $form_id = sqlvalue("SELECT id FROM Tablename WHERE id = '{$recID}'");  // This gets data for the current record

  // I store the root URL of our home page in a table, we need that for the link in the body
  $home = sqlvalue("SELECT Home FROM ConfigKeys LIMIT 1");
  
  // This builds the email header
  $to = sqlvalue("SELECT Request_To FROM ConfigKeys LIMIT 1");
  $from = sqlvalue("SELECT Request_From FROM ConfigKeys LIMIT 1");
  $subject = sqlvalue("SELECT Request_Subject FROM ConfigKeys LIMIT 1")." - ".$recID;
  
  // This builds the body with the link to the record
  $body = sqlvalue("SELECT Request_Body FROM ConfigKeys LIMIT 1").
        $lf.$lf.$record.
        $lf.$lf."To view this record please go to: ".$lf.
        $home.
        "Tablename_view.php?SelectedID=$recID".$lf;
I ended up using php to send the email. I think there is an API in AG to do that, probably cleaner, but I had already done this.

I needed to do the button. You can add this directly in the hook I would think, simpler, not having to mess with the button part or the querystring part.

Good luck.

~Paul

Moh Youba
Veteran Member
Posts: 228
Joined: 2017-03-12 09:31

Re: Email notification to all group members

Post by Moh Youba » 2020-08-02 18:17

Hello Paul

Thank you for your help, I have the library and I am going to try.

Best regards

Post Reply