Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Monday, August 18, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - SalesLogix Scripting & Customization
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Scripting & Customization | New ThreadView:  Search:  
 Author  Thread: Open a Crystal Report, export as PDF, add to attachments and send in email via a button
Chris Schone
Posts: 8
 
Open a Crystal Report, export as PDF, add to attachments and send in email via a buttonYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Nov 07 11:59 AM
I was wondering if it possible to do the following on one button.
I have a button that creates a report off an Opportunity that needs to be exported to a PDF.
Saved on the opportunity as an Attachment and sent in an email to a defined person.
I'm trying to cobble something together and any advice direction would be appreciated.
-Chris
[Reply][Quote]
Mark Richardson
Posts: 25
 
Re: Open a Crystal Report, export as PDF, add to attachments and send in email via a buttonYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 15 Nov 07 1:38 AM
Hi Chris,

The following does all but the Attatchment (which i'm sure is quite simple, maybe using the 'Application.BasicFunctions.InsertFileAttachment ?). As this script saves a pdf into a folder, this could be used as the attachment and then maybe deleted from the network folder once attached...
Another thing to note, depending on how your Corporate email system is configured (this requires outlook), you may find that an Outlook message pops up when running this routine. This is a standard outlook feature and can be worked around by installing a small app, available at
http://www.contextmagic.com/express-clickyes/
There are ways of getting Exchange Server to stop this pop-up but you'll need to look that up as it's not a simple tick-box - it's fairly hefty!

Sub SendOrderConfirmation

Dim filesys, strpath, strReportFile, strReportName, CRXReport, objRDC
Dim cid, first, last, ufirst,ulast,utitle


Dim email

email = GetField("EMAIL", "CONTACT", "CONTACTID ='" & cid & "'" ) '<- cid variable needs to be the contactid
first = GetField("FIRSTNAME", "CONTACT", "CONTACTID ='" & cid & "'" )
last = GetField("LASTNAME", "CONTACT", "CONTACTID ='" & cid & "'" )
ufirst = GetField("FIRSTNAME", "USERINFO", "USERID ='" & Application.BasicFunctions.CurrentUserID & "'" )
ulast = GetField("LASTNAME", "USERINFO", "USERID ='" & Application.BasicFunctions.CurrentUserID & "'" )
utitle = GetField("TITLE", "USERINFO", "USERID ='" & Application.BasicFunctions.CurrentUserID & "'" )

if email = ""
msgbox "Order Confirmation cannot be sent as this Contact has no recorded email address",vbExclamation,"No Email Address"
End If

set filesys = CreateObject("Scripting.FileSystemObject")

strpath = "\\steljes.ads\SLX\Orders\" '<- This is a Read/Writable shared drive where the pdf is stored


If Not filesys.FolderExists(strpath) Then
filesys.CreateFolder(strpath)
End If

strReportFile = strpath & Application.BasicFunctions.GlobalInfoFor ("OppID") & ".pdf" '<- This is the name of the pdf file
If (filesys.FileExists(strReportFile)) Then
filesys.DeleteFile(strReportFile)
End If
Set filesys = Nothing

Set objRDC = CreateObject("CrystalRuntime.Application")
Set CRXReport = objRDC.OpenReport("\\steljes.ads\SLX\order.rpt") '<- This is where the Crystal Report is held

CRXReport.RecordSelectionFormula = "{OPPORTUNITY.OPPORTUNITYID} = '" & Application.BasicFunctions.GlobalInfoFor ("OppID") & "'" '<- This line pumps (in this case) the OpportunityID into the Crystal Report
CRXReport.ExportOptions.DestinationType = 1
CRXReport.ExportOptions.DiskFileName = strReportFile
CRXReport.ExportOptions.FormatType = 31
CRXReport.Export False

Set CRXReport = Nothing
Set objRDC = Nothing
'================ send the mail + attachment ===================================
Dim oOApp
Dim oOMail
Dim olByValue
Dim vat,pr

Set oOApp = CreateObject("Outlook.Application")
Set oOMail = oOApp.CreateItem(olMailItem)
With oOMail
.To = email
.Subject = "SalesOrder Confirmation"
.Body = "Dear " & first & "," & chr(13) & chr(10) & chr(13) & chr(10)
.Body = .Body & "Please find attached details of your order placed recently with us." & chr(13) &chr(10) & chr(13) &chr(10)
.Body = .Body & "Please note that this is confirmation of receipt of order only." & chr(13) &chr(10)
.Body = .Body & "Shipping is subject to stock and payment terms." & chr(13) &chr(10) & chr(13) &chr(10)
.Body = .Body & "Your order reference is " & txtDescription.Text & chr(13) &chr(10) & chr(13) &chr(10)
.Body = .Body & "If you require confirmation, please contact me." & pr & chr(13) &chr(10) & chr(13) &chr(10)
.Body = .Body & "Best regards," & chr(13) & chr(10) & chr(13) & chr(10)
.Body = .Body & ufirst & " " & ulast & chr(13) & utitle

.Attachments.Add strpath & Application.BasicFunctions.GlobalInfoFor ("OppID") & ".pdf"' '<- Gets the pdf that was created earlier and attaches it
.Display <- This will Pop the Outlook Send window to the user
'.Send <- This would automatically (without popping the Outlook Send window) send the email + attachment
End With
Set oOApp = Nothing
Set oOMail = Nothing
End If
[Reply][Quote]
Chris Schone
Posts: 8
 
Re: Open a Crystal Report, export as PDF, add to attachments and send in email via a buttonYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 15 Nov 07 7:43 AM
Thanks for the info.
I am getting a error with this line
CRXReport.Export False

It gives me a login error?
"Logon failed.
Details : [Database Vendor Code: -2147217843]
Any ideas?

I really appreciate you help.
-Chris
[Reply][Quote]
Mark Richardson
Posts: 25
 
Re: Open a Crystal Report, export as PDF, add to attachments and send in email via a buttonYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 15 Nov 07 10:31 AM
Hi Chris,

I believe this is due to the write access security to the folder the pdf is saved off to - the line below from my original reply denotes the location of the pdf saved off file.
Make sure the SLX Server service account has read/write access to this location

strpath = "\\steljes.ads\SLX\Orders\" '<- This is a Read/Writable shared drive where the pdf is stored

Hope this resolves it

Mark
[Reply][Quote]
Chris Schone
Posts: 8
 
Re: Open a Crystal Report, export as PDF, add to attachments and send in email via a buttonYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 15 Nov 07 1:26 PM
It's working now!
Thanks for your help.
Now my next task is to take the PDF and save it as an attachment on the Opportunity.
Any thoughts?
[Reply][Quote]
Vladimir
Posts: 93
 
Re: Open a Crystal Report, export as PDF, add to attachments and send in email via a buttonYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 16 Nov 07 1:11 AM
Use Application.BasicFunctions.InsertFileAttachment to save as attachment with standard form dialog.
If you do not want use standard attachment dialog, you need copy file to attachment folder, insert record to ATTACHMENT table and update attachment with Application.BasicFunctions.UpdateFileAttachment.

Try Application.BasicFunctions.QueMessage to send email. There is example in "Sub SendEmail" of Opportunity Detail.
[Reply][Quote]
Chris Schone
Posts: 8
 
Re: Open a Crystal Report, export as PDF, add to attachments and send in email via a buttonYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 29 Nov 07 7:19 AM
Thanks Vladimir
Do you know how to pass the directory and filename of the file in order to bypass the initial dialog screen?
I would like it to default the path and name so that the diaglog box to Add Attachment already has the filenname so all the user has to do is click ok.
Any thoughts?
-Chris
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 8/18/2025 6:35:43 AM