Crystal Reports formula method, GroupName - crystal-reports

I am fixing some old reports and have come across the method GroupName. I cannot find exactly what it does and am coming for support. For that matter, is there an online reference that contains a list of the built it methods in CR, parameters, etc.?

GroupName just returns a string of... well, the current Group Name. This is either just the field you were grouping on, or is a value customized via the Group Expert -> Options (Change Group Options) -> "Customize Group Name Field". It's whatever displays in the group tree.
If it's not listed in the Crystal Reports Online Help, which is oddly the case with GroupName, then your best bet is some good, old-fashioned Googling. I'm not sure of any resource other than commercial products that lists descriptions and usage instructions for all the functions, properties, etc.
EDIT: You have to pass the field you're grouping on. So, for a random example, GroupName(Patient.Patient_Type_Code) might return strings "Therapy", "Rehab", etc. from a numeric type code you're grouping on.

Related

adding up specific mergefield values in word

I have a table in a word document that has three colums and all fields are mailmerge fields from an external IT system.
There are three columns displaying the fields:
Charge Description
Charge Value (£)
Eiligible? (yes/no)
I am trying to create a field that adds up all eligibale charges so that only charge values that show a "yes" in the eligigble field are included. Does anyone know if this is possible? I have tried creating a formula but can't get it to work. Also, I would assume at some point an if statment is required so that it only includes the eligible charge.
Has anyone done anything similar before and if so, would they mind sharing how it was achieved?
Many thanks
You can do some things with expression fields (created in Word with CTRL-F9). This will look like {} and you can insert the expression. eg {{MERGFIELD charge} + {MERGEFIELD charge2}}. Since however you want to check multiple values and then create an expression, its probably easier to use a macro. The macro would contain your logic, then set the fields in the document accordingly.
Here are two external links since I can't reproduce a useful amount the content here because it's a verbose answer to a potentially deep question:
Expression Fields
Merge fields
I hope that helps.

SSRS subquery based on other query

I'd like to make an overview of projects.
This contains some fixed info; table projects joined with some other tables.
Now the report needs to have some subqueries: how many sales per salesman, how many is in transit, inventory, ... and so on.
I have a tablix with grouping on project (as to create an excel with one worksheet per projet).
How would I go about executing a new subquery per project (f.e. select owner, sum(totalprice) from opportunities where project=xxx group by owner)
I know I could achieve this with subreports; but as I will have about 10 subreports, I was hoping I could solve this with extra datasets and some filtering (and thus keep all logic in one file).
What's the best way to achieve this?
I would create a dataset with this query:
select owner, project, sum(totalprice) as totalprice from opportunities group by owner, project
Next, in your tablix where you want to display owner and totalprice info, you will have an expression like this:
=LOOKUP(Fields!<FirstDataSetProjectFieldName>.Value, Fields!project.Value, Fields!owner.Value, "<NewDatasetName>")
The above code will send the value of the project you are searching for, match it with a the same field in your new dataset, then return the requested value from the new dataset. You can obviously do this for totalprice as well.
Check out the documentation for LOOKUP to get a better handle on it but I think this is the solution you are looking for.

Prioritise which identifier to use

My crystal report pulls data about books, including an identifier (isbn, issn order number etc.), author, and publisher.
The ID field stores multiple ways to identify the book. The report displays any of the identifiers for that record. If one book has two identifiers; issn and order number, the report currently displays one apparently at random.
How can I make it prioritise which type to use based on a preset order? I figured some sort of filter on the field could work, but I haven't figured out how. I can't edit the table, but I can use SQL within the report.
If all the different types of ID are stored in a single field, your best bet is to use a SQL Command inside your report to separate them into multiple virtual fields.
Go to Database Fields / Database Expert, expand the connection you want to use, and pick Add Command. From here you can write a custom SQL statement to grab the information you're currently using, and at the same time separate the ID field into multiple different fields (as far as the report will be concerned, anyway. The table will stay unchanged.)
The trick is to figure out how to write your command to do the separation. We don't know what your data looks like, so you're on your own from here.
Based on the very little information that you have provided and if i was to make a guess.I suggest you make use of the formula field in your report and then use something like this to accomplish your goal.
IF ISNULL{first_priority_field_name} OR {first_priority_field_name} = '' THEN
{second_priority_field_name}
ELSE
{first_priority_field_name}
Use nested IF statement in case there are more than 2 identifier fields.

Apply a Report filter in code

My particular, specific issue is probably too localized, but the general question I'm about to ask is something I'm sure others will ask and have wondered:
General question: In Sql Server Reporting Services, is it possible to apply a filter to a report in code? If not, is it possible to use branching in the report filter based on the value of a variable, and can you point me to documentation or explain how to do it.
My specific example follows, to expand on what I mean by the above, in case I worded it badly:
I'm learning SSRS and the docs and Google are coming up short.
The desired effect is that we have a report based on an incident tracking system. In this system, we have various teams that can track incidents: IT Ops, Development, Security, etc. Each of these teams have team members assigned.
We have a base report that displays ALL incidents.
We have added a boolean parameter named "LimitByTeam", which produces a CheckBox on the report as you'd expect.
We have added a String parameter that accepts multiple values. The allowed values come from a data set that lists the teams. This has added the expected drop-down list to the report, allowing users to select one or more teams.
We added a dataset that contains team and team member.
If the CheckBox is NOT selected, we want to display all incidents. (The default)
If it IS selected, we want to have the report to filter based on the login ID of the person who created the incident ticket.
Were I to do this in SQL, I'd do it as
Select
(ticket fields)
From
Table
WHERE TicketCreator IN (
Select LoginId FROM TeamMembersTable
WHERE TeamName in ('IT Ops', 'Developers'))
In SQL, or in VB, etc, this would be simple.
In SSRS I'm not figuring out quite how to do this. I've gotten as far as figuring out that I can use Custom Code to do more complex logic using VB (and it appears to be VB.NET. HOORAY! Familiar territory)
So I've added custom code and verified that I can read the value of the report parameter, but I can't figure out for the life of me how to apply a filter if the parameter value is True. Here's what I've got.
Public Sub ApplyTeamFilter()
' Report.Parameters("LimitByTeam") is a
' boolean report parameter that I'm able to access
' so I've got the IF statement worked out
If Report.Parameters("LimitByTeam").Value = True Then
' Pseudo-code - I'm looking for something like Report.Filters.Add(filterstatement)
' Alternatively a way to change this to a function to return a list of items from
' the Team MembersTable table and use it in a custom expression.
End If
End Sub
The problem is that I can't seem to find a Filters property on the Report object, or any method that lets me find it. Since I couldn't find it there, I expanded my search to everything in this section of the MSDN library and can't find it, or anything even remotely resembling a way to do what I'm attempting.
I'm also trying to do something like this because I think I see a way to use this function:
Public Function IsLoginIdInTeam(ByVal LoginId as String, byVal Team As String) As Boolean
' Report.Parameters("LimitByTeam") is a
' boolean report parameter that I'm able to access
' so I've got the IF statement worked out
If Report.Parameters("LimitByTeam").Value = False Then
Return True ' Default
Else
' Access the TeamMembers table and look for a match
' Something like
' Convert.ToBoolean(Report.DataSets!TeamMembers.Compute(Count, "TeamName = '" & Team & "' AND LoginId = '" & LoginId & "'")
End If
End Function
But I can't figure out how to access the Data Sets in the report, either, much less the syntax for interacting with them. The pseudocode works with a System.Data.DataTable, but I suspect SSRS DataSets are a different beast.
Am I missing something blindingly obvious? Should I be giving up on filtering this way in the report, and try another track, like changing the original query in the DataSet?
I'm not a huge fan of boolean parameters in SSRS (or BIT in SQL for that matter.) You can't write things like
WHERE #MyBool OR #MyOtherBool
It needs to be
WHERE #MyBool = 1 or #MyOtherBool = 1
So if I have an SSRS report with a boolean called MyBoolParam and a multivalue text parameter called MyMultiSelectTextParam , a SQL query like this will work:
SELECT
MyField,
MyOtherField
FROM
MyTable t
WHERE
#MyBoolParam = 1
OR
t.MyField IN ( #MyMultiSelectTextParam)
(My preferred alternative to boolean parameters is actually a string with possible values, but it would be handled in the query in the same way.)
If you can't easily change your SQL query (such as using a third party SP) then you can also accomplish the same thing by adding a filter to the SSRS DataSet. Right click on the DataSet in the Report Data pane and look at the Dataset Properties. The Filters pane will let you add criteria that are evaluated for each row. I haven't used these as much with multivalue parameters, but the IN Operator should work for that.

Dynamically change parameters based on the value of another parameter?

I have a crystal 2008 report that allows users to group to two levels.
I have two parameters, using which users can select which attribute they want to group on.
The two params are of type string and the list of values is static. Both levels have the same options to group on.
Is there someway to filter the list based on what they selected for param 1. So that they cannot group on the same thing twice.
I don't think it's possible. You can cascade dynamic parameters link Country, State but not how you want to.
How many options do they have to choose from? Do they normally choose anything other than a few different combinations from the maximum?
I think you're options are to either leave it as is (allowing them to pick the same thing for both groups). Or create a single parameters which looks like- Group by:
Date, Country
Type, Country
Date, Type
etc
Short answer: not possible.
Options:
create a custom UI that does what you want to do
if the list of grouping fields aren't too long, you could combine the two parameters into a single one, then list the options that you want to support. For example, if you have 3 grouping fields (A,B,C), your single, combined parameter would be A->B, B->A, B->C, C->B, A->C, C->A.