Solved

Passing parameters in formula field  to main report, Java, Crystal Reports , crjava-runtime_12.2.215

Posted on 2013-02-02
12
1,711 Views
Last Modified: 2013-03-16
I am unable to pass the value in the formula field in the crystal report though java.
there is a class with the name "FormulaFieldController" but there is no method in that by which we can set the values in the formula field.

Since the report is already created with few formula fields and are calculated on the basis of the parameter passed.


Please teach me how to send the value in the formula field?

Source code is given below

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@page import="com.crystaldecisions.reports.sdk.*"%>
<%@page import="com.crystaldecisions.sdk.occa.report.lib.*"%>
<%@page import="com.crystaldecisions.sdk.occa.report.data.*"%>
<%@page import="com.crystaldecisions.report.web.viewer.*"%>
<%@page import="com.crystaldecisions.reports.sdk.*"%>

<%
      String REPORT_NAME = "Report1.rpt";
      //Refer to the Viewers SDK in the Java Developer Documentation for more information on using the CrystalReportViewer
      //API.
      ReportClientDocument reportClientDoc = new ReportClientDocument();
      reportClientDoc.open(REPORT_NAME, 0);
      
      CrystalReportViewer viewer = new CrystalReportViewer();
      viewer.setOwnPage(true);
      viewer.setOwnForm(true);
      viewer.setPrintMode(CrPrintMode.ACTIVEX);
      session.setAttribute("reportSource",
                  reportClientDoc.getReportSource());
      Object reportSource = session.getAttribute("reportSource");
      

            
      viewer.setReportSource(reportSource);
      //Render the report.
      viewer.processHttpRequest(request, response, getServletConfig()
                  .getServletContext(), null);
%>
0
Comment
Question by:Rocking
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 18

Expert Comment

by:vasto
ID: 38846788
Create a parameter and use it inside the formula. By setting the parameter value you can change the behavior and the result of the formula.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 38846980
Why do you think you need to change the formula?

mlmcc
0
 

Author Comment

by:Rocking
ID: 38848050
@mlmcc
Why do you think you need to change the formula?

I don't need to change the formula,what i need is formula value is displayed as it is passed from the screen i.e jsp file.
Like for instance we need to show the title of the application which depends upon the locale of the client.There is a formulate field with the name "@title",just need to set the value in this field.


@vasto
Create a parameter and use it inside the formula.
I cannot modify the report layout nor added parameter in the same.

Reg parameter i am using on filed whose value i set though java code,even though i am setting the default value,the prompt message always appears asking for the value.
How can i avoid such prompt in cr viewer?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 100

Expert Comment

by:mlmcc
ID: 38848714
TO avoid the parameter prompt you have to pass the values from the application.  
I don't see the code that is setting the values

Default values are just that default and are displayed as the default value in the parameter screen.  They cab be accepted or changed by the user.

There may be an option on the call to the viewer to disable the prompts.

In VB6 methods you can set the formulas with a statement like

  crRptObj.Formulas(1) = " 'Text You Want to see' "

In general if you want a formula to show a value passed in by the user it is easier to use a parameter and just display it.

mlmcc
0
 

Author Comment

by:Rocking
ID: 38851747
In the view i couldn't find any such method to block the prompt message.
I am sending the parameters using the below code

ParameterFieldController paramController = reportClientDoc.getDataDefController().getParameterFieldController();
paramController.setCurrentValue("","id","20");


Yes your are correct,in vb it is possible to set the value of the formula field through code.

In general if you want a formula to show a value passed in by the user it is easier to use a
parameter and just display it.

Since i cannot modify the code therefore i need to send the value using the formula field.
Please let me know if it is possible.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 38853608
This claims to have a sample for doing it

http://wiki.sdn.sap.com/wiki/display/BOBJ/Crystal+Reports+Java++SDK+Samples

mlmcc
0
 

Author Comment

by:Rocking
ID: 38855980
I have already gone through the above link before and found the sample for creating the formula field sample code.

But what i need is to pass to set value in the existing formula field in the report?

With the help of below code i am able to get the object of the formula field from the report file

 DataDefController dataDefController = clientDoc.getDataDefController();
 IField field = dataDefController.findFieldByFormulaForm( "{table.field}" );

As per the above code it returns the object of "IField ".

But unable to find out how to set the text value?
0
 
LVL 18

Expert Comment

by:vasto
ID: 38856280
him121, I don't know how is in Java but in .NET ReportDocument provides a method SetParameterValue. If you set the parameter values correctly the parameter dialog  will be not shown.
My advice is to resolve your problem with the parameters and use a parameter value to set the report behaviour instead of trying to change a formula.
0
 
LVL 7

Expert Comment

by:gudii9
ID: 38857087
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 38858145
Try something like

 field  =  "5"

What do you want to set the formula to?

mlmcc
0
 

Accepted Solution

by:
Rocking earned 0 total points
ID: 38860427
I had tried but no luck.
Since the return type of the formula object is of "IField " 

 DataDefController dataDefController = clientDoc.getDataDefController();
 IField field = dataDefController.findFieldByFormulaForm( "{table.field}" );

and there is no such method in IField  to set the text,however there is such method in FormulaField class. Please refer below url

http://help.sap.com/javadocs/cr/xi/jrc/en/com/crystaldecisions/sdk/occa/report/data/FormulaField.html

I want to know how can i set the text in FormulaField?
0
 

Author Closing Comment

by:Rocking
ID: 38991473
No reply on this question
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat startup error 5 70
Page n of M in Crystal reports not calculating correctly 4 19
String array comparison 4 34
Html Table Looping (part 2) 5 12
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question