Alpha Video Training
Results 1 to 9 of 9

Thread: Emailing a Report using Javascript Event

  1. #1
    Member
    Real Name
    Scott Binger
    Join Date
    Oct 2011
    Posts
    291

    Default Emailing a Report using Javascript Event

    Hi All,

    I'm trying to email a simple report using the "Open a Report, Label or Letter layout" Javascript event. Screenshot attached. When I attempt to fire the event (via an on-click event on a button), nothing happens - no error message, no "wait" dialog - nothing.

    I have confirmed that the report opens/downloads fine on its own (when "Email Report" is not selected). I have also confirmed that my default email settings are working.

    I've used XBasic and Mandrill in the past to accomplish this, but would rather stick to the Action Javascript if I can, especially since Alpha has made it available.

    Any help would be greatly appreciated.

    Scott
    Attached Images Attached Images

  2. #2
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,324

    Default Re: Emailing a Report using Javascript Event

    You've not detailed what Alpha version/build you're using. In build 5487 up to today's pre-release 5589 I am getting this error in the console.

    email_report_error.PNG

    Could you confirm if you're getting the same error?

    When I run the report action, within the development environment, the Alpha UI goes nuts for about 10 seconds, then settles down and I get the Internal Server error posted. This error seems like a bug. My interanl email settings seem ok... email tests within settings go through without issue.

    Today's pre-release is supposed to be 5591... but Alpha cannot even get that right these days... it's actually 5589.

  3. #3
    Member
    Real Name
    John Mucci
    Join Date
    Nov 2010
    Location
    New York
    Posts
    297

    Default Re: Emailing a Report using Javascript Event

    I Handled it with an Xbsic function. Not sure if this helps.

    Code:
    Function print_bill as c (e as p)
    
    dim reportname as c
     printoptions = ""
     args = ""
     options = ""
     reportName = "Bill_Approve@[test]\\bill_approve.set"
    
     filename = "C:\Users\rciadmin\Documents\Old_Alpha\Shipment_Database\Bill_Approve.pdf"
     vReport = a5w_report_saveas(reportname,"PDF","","",filename,global_variables(),printOptions,args,options)
    
    dim pm as P
    dim ps as P
    if (email_smtp_open(ps, "rcismtp.dtsehost.com", 2525, "XXXXX.com", "Your Password")) then
     pm.to = "xxxx.com, xxxx.com,xxxx.com"
     pm.from = "xxx@xxx.com"
     pm.subject = "Wire/Checks are approved for "+ date() + "  Approved by  " + SESSION.CURRENTUSERNAME
     pm.message = "Wire/Checks are approved "
     pm.attachments =  <<%a%
    C:\Users\rciadmin\Documents\Old_Alpha\Shipment_Database\Bill_Approve.pdf
    %a%
    
     pm.html_message = "This is the message in HTML"
     email_smtp_send(pm, ps)
    end if
    email_smtp_close(ps)
    end function

  4. #4
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,324

    Default Re: Emailing a Report using Javascript Event

    John... to confirm... this works for me... no errors.

  5. #5
    Member
    Real Name
    Scott Binger
    Join Date
    Oct 2011
    Posts
    291

    Default Re: Emailing a Report using Javascript Event

    John - sorry for the delayed response and thank you for that function. Having a bit of an issue with it on my end and I think it may be the reportName. Do you know the correct syntax if the report is a project report?

  6. #6
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,324

    Default Re: Emailing a Report using Javascript Event

    This is the XBasic code I tested. The report has been published to a folder under A5Webroot.

    Code:
    function emailPDFRpt as c (e as p)
    
    dim reportname as c
    printoptions = ""
    args = ""
    options = ""
    
    reportName = "D:\A5Webroot\AlphaTest\rpt_Customers_Conditional.a5rpt"
    
    filename = "D:\UserFiles\test.pdf"
    vReport = a5w_report_saveas(reportname,"PDF","","",filename)
    
    dim pm as P
    dim ps as P
    dim result as l
    
    result = email_smtp_open(ps, "smtp.myemailsmtp.com", 465, "myacct@email.com", "mypw", "SSL")
    if result then	
    	pm.to = "toaddr@gmail.com"
    	pm.from = "fromaddr@rogers.com"
    	pm.subject = "Test"
    	pm.message = "Test"
    	pm.attachments =  <<%a%
    D:\UserFiles\test.pdf
    %a%
    
    pm.html_message = "This is the message in HTML"
    email_smtp_send(pm, ps)
    end if
    email_smtp_close(ps)	
    	
    end function
    Last edited by Davidk; 02-01-2019 at 02:34 PM.

  7. #7
    Member
    Real Name
    Scott Binger
    Join Date
    Oct 2011
    Posts
    291

    Default Re: Emailing a Report using Javascript Event

    Thanks David!

  8. #8
    Member
    Real Name
    Scott Binger
    Join Date
    Oct 2011
    Posts
    291

    Default Re: Emailing a Report using Javascript Event

    David - this worked like a charm. One final question: If I am dynamically setting filename (i.e. "D:\UserFiles"+e.dataSubmitted.somecontrolvalue), how would I set pm.attachments to be the same name? I tried using "D:\UserFiles"+e.dataSubmitted.somecontrolvalue but it threw back an error.

    Thank you!

  9. #9
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,324

    Default Re: Emailing a Report using Javascript Event

    You can use the function STRITRAN. You also need to be cautious with setting the filename.

    Code:
    filename = "D:\UserFiles\\" + e.dataSubmitted.pdfFileName
    Note the double backslash... XBasic thinks your escaping something otherwise.

    For pm.attachments, you can do this...

    Code:
    	pm.attachments =  <<%a%
    D:\UserFiles\replaceWithPDF
    %a%
    
    pm.attachments = stritran(pm.attachments,"replaceWithPDF",e.dataSubmitted.pdfFileName)
    In the pm.attachments string, replaceWithPDF is the substring you want to replace.

    If you don't want to bother with stritran you can just assign a string value to pm.attachments...

    Code:
    pm.attachments =  "D:\UserFiles\\" + e.dataSubmitted.pdfFileName
    It is probably the single backslash before the end quote that's giving you the error.

Similar Threads

  1. How to copy event Action Javascript to another event?
    By Ben S. in forum Mobile & Browser Applications
    Replies: 6
    Last Post: 01-12-2018, 09:03 PM
  2. Replies: 9
    Last Post: 05-05-2014, 03:08 PM
  3. Emailing a report.
    By Atta in forum Application Server Version 10 - Web/Browser Applications
    Replies: 4
    Last Post: 05-29-2011, 02:03 AM
  4. Specify filename of Javascript Event report
    By christappan in forum Application Server Version 10 - Web/Browser Applications
    Replies: 0
    Last Post: 08-04-2010, 12:58 PM
  5. default filename on report thru Javascript Event
    By christappan in forum Application Server Version 10 - Web/Browser Applications
    Replies: 0
    Last Post: 04-08-2010, 05:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •