cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic list of values in Crystal report

Former Member
0 Kudos

Hi,

I designed one crystal report with parameter type for list of values are static and dynamic.

Staic Type(City names are manually entered by me at design time)

Dynamic Type( I created a link for City parameter with database, so it should display whatever data available in the database for that particular field)

For static I can fetch the data. but For dynamic list of values, it should fetch the value from Database.

Is there any APIs available to identify whether it is static or dynamic?

How to handle this scenario using CR API's?

Please share your thoughts on this...

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I am using Crystal reports for visual studio 2010.

I want to write a dialog which should display a list of value for dynamic parameters.

As of now i can handle this for static parameters using "parameterFieldDefinition.DefaultValues.Count". This defaultvalues.count return proper value for static parameters. But for dynamic parameters it is always zero.

so please help me to handle dynamic parameter details using CR APIs in C#

DellSC
Active Contributor
0 Kudos

If you're going to display the list of values in your application instead of using the default Crystal parameter entry screen, then you don't need to set this up as a dynamic parameter in Crystal - instead you'll get the list directly from the database in your application, allow the user to select from it, and then set the parameter value in code from your application.

However, if you're using the default Crystal parameter screen, here's what you'll do in your report to get this to work:

1.  Add the table with the city list in it to the report in the Database Expert.  DO NOT link this table to any other tables in the report.  Crystal will throw a warning stating that this is generally not supported, but it will work in this case so you can ignore the error.

2.  Edit the City parameter, make it dynamic, and select field(s) from the table you added in Step 1 ONLY.  DO NOT use any fields from any other table in the parameter definition.

3.  DO NOT use fields from the table in Step 1 anywhere else on the report - this will only be used for the parameter.

You should now be able to dynamically get the city names in the Crystal parameter entry screen when you run the report.

-Dell

Former Member
0 Kudos

Hi Dell,

Thanks for the reply.

I designed report with dynamic parameters. I want to launch the parameter dialog for both static and dynamic parameters using CR APIs at run-time.

I could launch the parameter dialog for static variables using CR API(Defaultvalues for parameterfield defintion). But for Dynamic parameters, I dont find any CR API's. Is there any API available to handle this? or How to handle this scenario at runtime??

DellSC
Active Contributor
0 Kudos

How are you "launching" the parameter dialog?  It should just automatically appear when you run/view the report, in which case it will show the dynamic values as well as the static values.

-Dell

Former Member
0 Kudos

I customized the dialog using CR API's

In the drop down I can List out the Static value details. But For Dynamic its not displaying...

Any CR API's available??

DellSC
Active Contributor
0 Kudos

There is no API for that that I am aware of.  However, or should know for sure whether that exists or if there's a work-around for your issue.

-Dell

0 Kudos

Hi Dell and Gallen,

There is one you can use actually. Here's how to:

public Boolean isParameterDynamic(CrystalDecisions.CrystalReports.Engine.ReportDocument rpt, int iCnt, bool YorN)

{

    if (rpt.DataDefinition.ParameterFields[iCnt].Attributes != null && rpt.DataDefinition.ParameterFields[iCnt].Attributes.ContainsKey("IsDCP"))

    {

        Hashtable objAttributes = rpt.DataDefinition.ParameterFields[iCnt].Attributes;

        YorN = (Boolean)objAttributes["IsDCP"];

        return YorN;

    }

    return YorN;

}

That should be able to tell you if it is or not. But you may not be able to hook into our Parameter UI for them in which case you will need to create your own Parameter Dialog box. but now you will know if they are dynamic or not.

Don

Former Member
0 Kudos

Thanks Don. The above piece of code is working and I can verify whether it is Dynamic or Static parameter using this code.

But I could not get Datasource details which is linked with that particular parameter. I want to list out all the values which is stored in the database for that parameter.

How can I get the DataSource details which is linked with particular field?

0 Kudos

HI Gallen,

This line will list the field the parameter was based on:

getDiscreteValues(paramfield);

getDiscreteValues(CrystalDecisions.ReportAppServer.DataDefModel.ISCRParameterField paramfield)

BrowseField collection has the field name

Don

Former Member
0 Kudos

Don,

I designed a report with two parameters (name - Static parameter and city - Dynamic parameter)

1. I gave default values for "Name" parameter

2. I assigned field name for City parameter, so which should display the values available in the particular database. (Association: Table: Student Field name: CITY)

I have added below piece of code in my existing code.

// To verify whether the parameter is "static" or "Dynamic".

CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc = rptDocument.ReportClientDocument;

Boolean YorN = false;

Hashtable objAttributes = parameterFieldDefinition.Attributes;

YorN = (Boolean)objAttributes["IsDCP"];

if (YorN) // if parameter is Dynamic

{

    foreach (CrystalDecisions.ReportAppServer.DataDefModel.ParameterField paramField in rptClientDoc.DataDefinition.ParameterFields)

    {

         MessageBox.Show(paramField.Name);

        MessageBox.Show(paramField.Description);

        MessageBox.Show(paramField.FormulaForm);

        if (paramField.BrowseField != null)

        {

            MessageBox.Show(paramField.BrowseField.Name);

        }

                   

    }

}

First I verified whether the parameter is Dynamic or Static. And if the parameter is dynamic , then I tried to access the field name which is connected against dynamic parameter. But this "paramField.BrowseField" is always NULL.

I want to access the field value which is assigned against Dynamic parameter. So If I get the field name then I need to write database connectivity code to fetch the value from database for that particular field.

Am I missing anything in the above code? or could you please explain how to get the database field name for dynamic parameters?

-Gallen,

0 Kudos

Hi Gallen,

I recall now I did ping R&D about this always returning NULL but I can't find their response.

I have to ask them again why this happens and if we can change it.

I do recall though the only way to make this work is to change the Prompt Text to have the field name in it:

Only way I could find to be able to retrieve it.

Don

0 Kudos

I've create a case for this issue now -

Incident 7889 / 2015 / ER - Dynamic Parameter BrowseField value

and a KBA - 2114469

Too late for SP 13 now so they'll have a look into it and see if they can add it in SP 14.

Don

Former Member
0 Kudos

Thanks Don. Please keep us updated.

Answers (0)