8/18/2025 8:27:47 AM
|
|
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!
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.
|
|
|
|
Open a Crystal Report, export as PDF, add to attachments and send in email via a button
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 |
|
|
|
Re: Open a Crystal Report, export as PDF, add to attachments and send in email via a button
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 |
|
|
| |
|
Re: Open a Crystal Report, export as PDF, add to attachments and send in email via a button
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 |
|
|
| |
|
Re: Open a Crystal Report, export as PDF, add to attachments and send in email via a button
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. |
|
|
| |
|
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!
|
|
|
|
|
|
|
|