Plex with Crystal Reports - VBScript runtime error

book

Article ID: 128114

calendar_today

Updated On:

Products

CA Plex

Issue/Introduction

Upgraded model to 7.2.1 and also upgraded to Crystal Reports 13.0.9, and now, the open script is getting an message. 

Script Error 
The script engine: Microsoft VBScript runtime error 
has reported the error : ActiveX component can't create object: 
'CrystalRuntime.Application' 
The statement which caused the error is: 
Set app = CreateObject("CrystalRuntime.Application") 

Script Error 
The script engine: Microsoft VBScript runtime error 
has reported the error: Object required: 'CrystalActiveXReportViewer1' 
The statement which caused the error is: 
CrystalActiveXReportViewer1.ReportSource=rpt 

Same model is currently working in Plex 7.1 and CR v11.

Environment

Release:
Component: CPLEX

Resolution

We have tried to create an interface over SAP Crystal Report .Net APIs and could make a call from Plex C++ function to invoke ExportToDisk API. 
Initially we tried to find equivalent object which can be created in intermediate interface and then can be passed back to Plex to assign it to Crystal Report ActiveX viewer - but could not find any such object exposed from Crystal report side. While trying to assign the ReportDocument object type, it was failing with casting issues - which is unsupported type conversion. Approaching to SAP Crystal Report Vendor can help in this regard if there is any workaround or possibility for this. 

We will be attaching the C# solution with VBScript code against this case for your reference. 

Details about the interface creation along with VBscript code: 

COM Wrapper over SAP Crystal Report v13.x .Net APIs. 

Create a C# project with following details. 
Visual Studio 2013 -> New Project -> Visual C# -> Class Library project type. 

<Please see attached file for image>

User-added image

Referenced two C# assemblies extension from SAP Crystal Report: 

<Please see attached file for image>

User-added image

Sign the built assembly by following option in Visual Studio IDE 
Right Click on project and select Properties and select Signing option in left pane. Choose a strong name key file by clicking on dropdown menu option, don’t setup password option. 

<Please see attached file for image>

User-added image

In provided sample, created an interface having implementation for Exporting report file to target format. Similar way, implementation can be added for other functionality provided by Crystal Report. 
You need to change the Interface accordingly as per your requirement. 

This function has three Input parameters, 
reportName - Report that needs to be converted to target format. 
reportFormat - Target format to be converted. 
destFileName - Converted file name. 

<Please see attached file for image>

User-added image

Build the project in release mode. The out of the provide sample project is - InterOPTestSample.dll. 

Now, time to register the built component so that we can consume the interface in Plex via VB Scripting. 
"C:\windows\microsoft.net\Framework\v4.0.30319\RegAsm.exe" /tlb:InterOPTestSample.tlb /codebase InterOPTestSample.dll 

Gacutil.exe allows you to install assemblies into the cache, remove them from the cache, and list the contents of the cache. 
"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\gacutil.exe" /i InterOPTestSample.dll 

This is it for Interface build and setup. Now let’s test the built interface. 

Place the following VBScript code in Plex source code object and invoke where required. 
We have hard coded the parameter value in VBScript but you can these as parameter to Plex pass and so on. 

------------ 
'Crystal Report – supported cxport format types. 
'enum ExportFormatType 
' { 
' NoFormat = 0, 
' CrystalReport = 1, 
' RichText = 2, 
' WordForWindows = 3, 
' Excel = 4, 
' PortableDocFormat = 5, 
' HTML32 = 6, 
' HTML40 = 7, 
' ExcelRecord = 8, 
' Text = 9, 
' CharacterSeparatedValues = 10, 
' TabSeperatedText = 11, 
' EditableRTF = 12, 
' Xml = 13, 
' RPTR = 14, 
' ExcelWorkbook = 15, 
' } 
Dim retRPTObj, repName, repFmt, repDestFile 
Set myObjCR = CreateObject("SAPCRNetAPIWrapper") 
if IsObject(myObjCR) then 
repName = "c:\sample.rpt
repFmt = 5 
repDestFile = "c:\sample1234.pdf
MsgBox "SAPCRNetAPIWrapper - object successfully created. " & Chr(13) & Chr(10) & "Exporting, " & repName & " --> " & repDestFile, vbOKOnly, "Crystal Report operation..." 
myObjCR.ConvertReportToPDF repName, repFmt, repDestFile
else 
MsgBox "SAPCRNetAPIWrapper - failed to create object. Make sure you have registered the component." 
end if 

There are two options explored to achieve the desired outcome. 

#1. Launching an application that has built with Visual Studio with SAP Crystal Report viewer would be viable solution. 
So below is the details how to launch EXE from Plex application. 

To start a program from within your application, use ‘OBWIN/Start an EXE Program’ source code API. 
This API has one input parameter. In your action diagram, set the value of Parameter String to the name of the program and any necessary arguments. 

#2. To get elevated permission while accessing COM Wrapper – start/run Plex IDE or EXE with ‘Run as Administrator’ option.
 

Attachments

1558689581562000128114_sktwi1f5rjvs16fz9.png get_app
1558689579620000128114_sktwi1f5rjvs16fz8.png get_app
1558689577692000128114_sktwi1f5rjvs16fz7.png get_app
1558689574891000128114_sktwi1f5rjvs16fz6.png get_app