Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Silver Super Contributor
Posts: 801
Registered: ‎03-24-2009
Accepted Solution

Crystal Reports, v7.5.1 and supplying filters

Hi

I'm pulling my hair on this - does anyone know how to supply a filter to a crystal report via code. I used the code from Kevin Noreus but it looks like this has changed from v7 to v7.5.1 ?

Set objReportConditions = New SLXReportConditions
objReportConditions.MainTable = "C_SALES_INVOICES"
objReportConditions.Connector = "ANY"

Set objCondition = New SLXReportCondition

objCondition.ConditionType = "Query"
objCondition.Table = "C_SALES_INVOICES"
objCondition.Field = "C_SALES_INVOICESID"
objCondition.Operator = cOperatorIs
objCondition.Value = ebID.Text

objReportConditions.Add objCondition

CrystalReportPreviewWithConditions "Account","Sales Invoice", objReportConditions


I just want to be able to filter by the ID (not a main id) - so I need to supply that. The above gives all sorts of errors about undimmed variables, not an object etc.

Just wondering if anyone has this working and an example ?

Thanks
Mike
Silver Super Contributor
Posts: 801
Registered: ‎03-24-2009

Re: Crystal Reports, v7.5.1 and supplying filters

OK, figured it out -

1) At the start of your script add:

Dim mConditionBuilderController, objReportConditions, objCondition

As global variables.

Then this is the calling script:

Set mConditionBuilderController = New ReportConditionBuilderController ' <<<< This was the missing line

Set objReportConditions = New SLXReportConditions
objReportConditions.MainTable = "C_SALES_INVOICES"
objReportConditions.Connector = "ANY"

Set objCondition = New SLXReportCondition

objCondition.ConditionType = "Query"
objCondition.Table = "C_SALES_INVOICES"
objCondition.Field = "C_SALES_INVOICESID"
objCondition.Operator = cOperatorIs
objCondition.Value = ebID.Text

objReportConditions.Add objCondition

CrystalReportPreviewWithConditions "Account","Sales Invoice", objReportConditions

Should then work OK !

Regards
Mike
Highlighted
Gold Super Contributor
Posts: 3,087
Registered: ‎03-19-2009

Re: Crystal Reports, v7.5.1 and supplying filters

Someone had to give you a kudo for this ;-)
--
RJ Ledger - rjledger@rjlSystems.net +1 603.369.3047 x101

".. Innovators in Mobility - Experts in Workflow Automation..."
http://www.rjlSystems.net - blog: www.rjlSystems.net/blog.html
Silver Super Contributor
Posts: 801
Registered: ‎03-24-2009

Re: Crystal Reports, v7.5.1 and supplying filters

Yep, they did - oh, wait - it was me :-)
Copper Contributor
Posts: 28
Registered: ‎04-01-2009

Re: Crystal Reports, v7.5.1 and supplying filters

Thanks Mike.  Again you are a life saver.  I had this on my "list of things to do" and now I don't need to. :smileyvery-happy:  My temp workaround was just to re-release the old scripts, but your solution is MUCH better.  Again, thanks for saving me a lot of work.

 

Ted 

Silver Super Contributor
Posts: 801
Registered: ‎03-24-2009

Re: Crystal Reports, v7.5.1 and supplying filters

Thanks Ted, I searched everywhere for this and couldn't find it ! However, there does seem to be an issue on re-running a report. Occasionally, I'll get an error (same report, same data) [mReportConditions doesn't support this property "clear"] but in the main it works. If you find a resolution to that PLEASE let me know !
New Member
Posts: 1
Registered: ‎12-11-2009

Re: Crystal Reports, v7.5.1 and supplying filters

Well Folks,

 

my users came up with a quiet complex report they want to preview by clicking an icon from the toolbar (not manouvering to reports, select report, current record, preview and so on). The Report itself is loaded with numbers of subreports (like "10 latest History Records", which I couldn't manage reliably in Crystal) so they are based on linked in SQL Views, scripted to the remote clients via osql -i<file doing view.sql> fired in Admin as a Remote Task).

 

So far so good but how to achiev?

 

I spent quite some time to pull all the bits and pieces from several posts and docs... and here we go: 

 

I've dev'd this 4 step "recipe":

 

1. Create Report

2. Create 1st Active Script

3. Create 2nd Active Script

4. Create Toolbar

 

Save Project and create Bundle (ALLLLL!!! on a Test System of course) to port it to Production later.

 

Step details:

 

1. Ceate Report:

 Most important is to place the Keyfield in the Report to manage filtering, obviously. In my case ACCOUNT:ACCOUNTID

 

2. Create 1st Script

This is a Script populating the CurrentAccountID into a global Var.

 

<code>

option explicit
sub Main

dim wpeAccID, g_wpeAccID

wpeAccID = Application.BasicFunctions.CurrentAccountID

Application.BasicFunctions.GlobalInfoSet "g_wpeAccID", wpeAccID

Application.BasicFunctions.DoInvoke "CrystalReportPreview", "ACCOUNT:Report you created"

end sub

</code> 

 

Save the Script as "Set CR global AccountID" or so. Will be needed later for the icon in the toolbar.

 

3. Create 2nd Script

This Script will pass the Filter Condition to the CR

 

<code>

option explicit
sub Main

Dim wpeCRID
wpeCRID = Application.Basicfunctions.GlobalInfoFor("g_wpeAccID")
if wpeCRID <> "" then
    Application.Basicfunctions.GlobalInfoClear "g_wpeAccID" 
    Application.BasicFunctions.ReportAddCondition "ACCOUNT:ACCOUNTID", "=", wpeCRID, "String", ""

end if

end sub

</code>

 

Save the Script as "Launch CR with Filter" or so

 

Now in Architect go to Manage -> Reports and double-click your Report.

On the Execution tab put this script on the when open event.

 

4. Create Toolbar

Now create a Toolbar and put "Standard Toolbar" as a Child, then "Your Report Name" as Child hereunder.

- Merge Rule: After Previous

- Select a funky glyph

- Action: Active Script.

- Argument: PersonalSmiley Frustratedet CR global AccountID

...

 

Sorted.

 

Put all the pieces in a bundle and don't forget the releases...

 

Hope that helps - any comments?

 

Regards

Achim