Sage 100

 View Only
  • 1.  (Tutorial) Launch Crystal Report Via Sage 100 Script

    Posted 08-15-2019 21:23
      |   view attached
    Figured I'd share a simple way to launch a Crystal Report via an external and internal script.

    Both scripts are also in the attached zip.

    On version 2017 and higher, you need to make sure to copy the MAS90\Home\pvxwin32.exe.config file to the location of pvxcom.exe and rename the copied pvxwin32.exe.config file to pvxcom.exe.config.

    pvxcom.exe should be in "Program Files (x86)\Common Files\Sage\Common Components" if on 64 bit windows and in "Program Files\Common Files\Sage\Common Components" if on 32 bit windows.

    When executing the script external, make sure the script file is executed by the 32 bit version of cscript.exe or wscript.exe if on 64 bit windows.

    The scripts currently preview the report but you can set export options as well.

    Internal.
    If IsObject(oSession) Then
    	sReportName = "Report1.rpt"
    	sReportTitle = "Report Test"
    	sPathRoot = ""
    	sPathRoot = oSession.PathCSRoot
    	Set oFileSystemObject = CreateObject("Scripting.FileSystemObject")
    	If Not(oFileSystemObject.FolderExist(sPathRoot)) Then sPathRoot = oSession.PathRoot
    	sReportPath = sPathRoot & "Reports\" & sReportName
    	bValidReportPath = oFileSystemObject.FileExists(sReportPath)
    	Set oFileSystemObject = Nothing
    	sErrorMsg = ""
    	If bValidReportPath Then
    		nReport_Rpt = 0 : nReport_Rpt = oSession.GetObject("SY_ReportEngine")
    		If nReport_Rpt > 0 Then
    			Set oReport_Rpt = oSession.AsObject(nReport_Rpt)
    			If oReport_Rpt.OpenReport(sReportPath) = 1 Then
    				oReport_Rpt.SetReportTitle sReportTitle
    				oReport_Rpt.SetPreviewOptions sReportTitle
    				If oReport_Rpt.DatabaseLogon() = 1 Then
    					oReport_Rpt.SetSelectionFormula("Not(IsNull({SO_SalesOrderHeader.CustomerPONo}))") ' Use this to set your own selection formula in Crystal Syntax.
    					oReport_Rpt.SetFormula "CompanyCode", """" & oSession.CompanyCode & """" ' Use this to set the value of the formula name specified in the first argument. You must respect the syntax specified in the formula in the report.
    					oReport_Rpt.Preview
    				Else
    					sErrorMsg = "Unable to logon to database." _
    					& vbCrLf & "Error Number: " & oReport_Rpt.sLastErrorNum _
    					& vbCrLf & "Error Message: " & oReport_Rpt.sLastErrorMsg
    				End If
    			Else
    				sErrorMsg = "Unable to open report." _
    				& vbCrLf & "Error Number: " & oReport_Rpt.sLastErrorNum _
    				& vbCrLf & "Error Message: " & oReport_Rpt.sLastErrorMsg
    				End If
    			End If
    			oReport_Rpt.CloseReport
    			Set oReport_Rpt = Nothing
    		Else
    			sErrorMsg = "Unable to get handle to SY_ReportEngine." _
    			& vbCrLf & "Error Number: " & oSession.sLastErrorNum _
    			& vbCrLf & "Error Message: " & oSession.sLastErrorMsg
    		End If
    	Else
    		sErrorMsg = """" & sReportPath & """ could not be found."
    	End If
    End If​




    External.

    Set oWScriptShell = CreateObject("WScript.Shell")
    sPathRoot = oWScriptShell.RegRead("HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\SOTAMAS90\Directory") ' Using the SOTAMAS90 DSN to determine path.
    Set oWScriptShell = Nothing
    sReportName = "Report1.rpt"
    sReportPath = sPathRoot & "\Reports\" & sReportName
    Set oFileSystemObject = CreateObject("Scripting.FileSystemObject")
    bValidReportPath = oFileSystemObject.FileExists(sReportPath)
    Set oFileSystemObject = Nothing
    sErrorMsg = ""
    If bValidReportPath Then
    	Set oProvideXScript = CreateObject ("ProvideX.Script")
    	oProvideXScript.Init(sPathRoot & "\Home") ' Make sure to set this path to point to the mas90 folder on the server if you don't use the SOTAMAS90 DSN.
    	Set oSession = oProvideXScript.NewObject("SY_Session")
    	Set oProvideXScript = Nothing
    	' UI object is needed if you want to see progress bars, message boxes, or preview the report.
    	If IsObject(oSession.oUI) Then 
    		Set oUI = oSession.oUI ' Use this to set your own object handle to the existing UI object.
    		' oSession.nTerminateUI ' Use this to terminate the UI if it exists and you don't need it.
    	Else
    		Set oUI = oSession.oInitiateUI() ' Use this to set your own object handle by initiating the UI object.
    	End If
    	' Make sure to specify credentials.
    	sUserName = "user"
    	sUserPassword = "password"
    	If oSession.nSetUser(sUserName, sUserPassword) = 1 Then
    		sCompanyCode = "ABC"
    		If oSession.nSetCompany(sCompanyCode) = 1 Then
    			sModuleCode = "S/Y" ' Set this to the module code that you intend to access in the X/X format.
    			sModuleDate = "20190815" ' This needs to be in yyyyMMdd format.
    			sModuleDate = oSession.sSystemDate ' Use this if you want to use the current system date returned by the SY_Session object.
    			oSession.nSetDate sModuleCode, sModuleDate
    			oSession.nSetModule sModuleCode
    			sReportTitle = "Report Test"
    			If oSession.nSetProgram(oSession.nLookupTask("SY_Listing_UI")) > 0 Then
    				nReport_Rpt = 0 : nReport_Rpt = oSession.nNewObject("SY_ReportEngine")
    				If nReport_Rpt > 0 Then
    					Set oReport_Rpt = oSession.oGetObject("SY_ReportEngine")
    					' Make sure your report has been converted to the correct level or else the report engine will not open it.
    					If oReport_Rpt.nOpenReport(sReportPath) = 1 Then
    						oReport_Rpt.nSetReportTitle sReportTitle
    						oReport_Rpt.nSetPreviewOptions sReportTitle
    						If oReport_Rpt.nDatabaseLogon() = 1 Then
    							oReport_Rpt.nSetSelectionFormula("Not(IsNull({SO_SalesOrderHeader.CustomerPONo}))") ' Use this to set your own selection formula in Crystal Syntax.
    							oReport_Rpt.nSetFormula "CompanyCode", """" & oSession.sCompanyCode & """" ' Use this to set the value of the formula name specified in the first argument. You must respect the syntax specified in the formula in the report.
    							oReport_Rpt.nPreview
    						Else
    							sErrorMsg = "Unable to logon to database." _
    							& vbCrLf & "Error Number: " & oReport_Rpt.sLastErrorNum _
    							& vbCrLf & "Error Message: " & oReport_Rpt.sLastErrorMsg
    						End If
    					Else
    						sErrorMsg = "Unable to open report." _
    						& vbCrLf & "Error Number: " & oReport_Rpt.sLastErrorNum _
    						& vbCrLf & "Error Message: " & oReport_Rpt.sLastErrorMsg
    					End If
    					oReport_Rpt.nCloseReport
    					Set oReport_Rpt = Nothing
    					oSession.nDropObject nReport_Rpt
    				Else
    					sErrorMsg = "Unable to get handle to SY_ReportEngine." _
    					& vbCrLf & "Error Number: " & oSession.sLastErrorNum _
    					& vbCrLf & "Error Message: " & oSession.sLastErrorMsg
    				End If
    			Else
    				sErrorMsg = "Unable to get security object." _
    				& vbCrLf & "Error Number: " & oSession.sLastErrorNum _
    				& vbCrLf & "Error Message: " & oSession.sLastErrorMsg
    			End If
    		Else
    			sErrorMsg = "Unable to set company." _
    			& vbCrLf & "Error Number: " & oSession.sLastErrorNum _
    			& vbCrLf & "Error Message: " & oSession.sLastErrorMsg
    		End If
    	Else
    		sErrorMsg = "Unable to set user." _
    		& vbCrLf & "Error Number: " & oSession.sLastErrorNum _
    		& vbCrLf & "Error Message: " & oSession.sLastErrorMsg
    	End If
    	Set oUI = Nothing
    	If IsObject(oSession.oUI) Then oSession.nTerminateUI
    	oSession.nCleanUp
    	Set oSession = Nothing
    Else
    	sErrorMsg = """" & sReportPath & """ could not be found."
    End If
    If sErrorMsg <> "" Then MsgBox sErrorMsg
    


    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------

    Attachment(s)



  • 2.  RE: (Tutorial) Launch Crystal Report Via Sage 100 Script

    Posted 08-16-2019 07:03
    This is amazing - I can't wait to test these!! Thank you!

    ------------------------------
    Amber Prayfrock, Blytheco
    ------------------------------



  • 3.  RE: (Tutorial) Launch Crystal Report Via Sage 100 Script

    Posted 08-19-2019 14:21
    Indeed! #KingOfDocumentation #script #scripting​​​​​

    ------------------------------
    ==================
    Rhonda McNamara
    Customer Success Manager
    Stewart Technologies, Inc.
    rsm@stewarttechnologies.com
    ------------------------------



  • 4.  RE: (Tutorial) Launch Crystal Report Via Sage 100 Script

    Posted 08-20-2019 13:21
    So what is the main business case use for the scripts?  How does it make the day in the life of the user easier?

    ------------------------------
    alan niergarth
    Velosio LLC
    ------------------------------



  • 5.  RE: (Tutorial) Launch Crystal Report Via Sage 100 Script

    Posted 08-20-2019 13:29
    I have a client that wants to print a cover sheet based on the AP invoice they enter.  They put the cover sheet with the documentation which is then microfiched.  We had a script button that printed the page from within AP entry.  Worked great in v2013, then something happened with the v2014 release and it quit working.  Client has had an unhappy face ever since.  We are hoping this script will make them smile again.

    ------------------------------
    Jeff Schwenk
    FORMER 90M Board Member
    Bottomline Software, Inc.
    Waynesboro VA
    540-221-4444
    ------------------------------



  • 6.  RE: (Tutorial) Launch Crystal Report Via Sage 100 Script

    Posted 08-20-2019 13:38

    This particular script was based off a script created to launch a crystal report added as a CUSTOM report to the menu with the report's selection formula being tied to the current record in sales order entry so the user doesn't have to specify a sales order number (and if a line is selected, that line's LineKey is added to the selection formula as well) in a runtime parameter.

     

    The code can also be adapted to export and email a PDF instead.

     

    Although this code doesn't have it in it, there is a recent post on sage city that I answered that shows how to set selection criteria on a report that uses report settings, like the AP Aged Invoice Report. So this can be adapted to schedule, export, and email a report that uses sage 100's work tables instead of having to redesign a report to use the standard tables so it can be used with VisualCut.

     

     

     

    Thanks

    David Speck

    TSS

    Sage | Sage 100 Certified Consultant

     



    ------Original Message------

    I have a client that wants to print a cover sheet based on the AP invoice they enter.  They put the cover sheet with the documentation which is then microfiched.  We had a script button that printed the page from within AP entry.  Worked great in v2013, then something happened with the v2014 release and it quit working.  Client has had an unhappy face ever since.  We are hoping this script will make them smile again.

    ------------------------------
    Jeff Schwenk
    FORMER 90M Board Member
    Bottomline Software, Inc.
    Waynesboro VA
    540-221-4444
    ------------------------------


  • 7.  RE: (Tutorial) Launch Crystal Report Via Sage 100 Script

    Posted 08-22-2019 08:30
    Taking a step further, could this work with Alerts & Workflow to trigger crystal reports using .wrk tables? Like sending invoice copies for collection without having to recreate the invoice from invoice history tables?

    ------------------------------
    alan niergarth
    Velosio LLC
    ------------------------------



  • 8.  RE: (Tutorial) Launch Crystal Report Via Sage 100 Script

    Posted 08-22-2019 08:36

    Yes it could.

     

     

     

    Thanks

    David Speck

    TSS

    Sage | Sage 100 Certified Consultant

     



    ------Original Message------

    Taking a step further, could this work with Alerts & Workflow to trigger crystal reports using .wrk tables? Like sending invoice copies for collection without having to recreate the invoice from invoice history tables?

    ------------------------------
    alan niergarth
    Velosio LLC
    ------------------------------


  • 9.  RE: (Tutorial) Launch Crystal Report Via Sage 100 Script

    Posted 09-23-2022 14:37
      |   view attached
    @David Speck II First thanks for the awesome script - giving me what I need to preview the report from a button script. The client is wanting this to print to a label printer, is it possible to print directly to a specified printer? not just preview or export? Any suggestions would be greatly appreciated.​

    ------------------------------
    Lisa Dion
    Vrakas/Blum Computer Consulting, Inc.
    ------------------------------

    Attachment(s)

    txt
    WTTagsReport.Printer.txt   2 KB 1 version


  • 10.  RE: (Tutorial) Launch Crystal Report Via Sage 100 Script

    Posted 09-26-2022 12:41
    Hi Lisa, 

    I have never tried printing directly to a printer from a Sage 100 task so I don't have any sample code to do so.  If you can't find a way to do it, then it should be possible to export to a PDF and then send the PDF to a printer using some shell commands.  You can always delete the file afterwards.

    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------