Custom Function addition in crystal Report - crystal-reports

I have to format a date string to a custom format like i need to convert "11/04/2016" to "11/D/2016". simply I have to replace the month number that is here 04 to an alphabet with the same sequence like 01 will be replaced by A and 02 by B and so on. I don't have any problem for writing logic for general purpose programming language. But I dont know how to add this custom functionality in crystal report.
I have checked formula fields but it seems they have predefined formulas whereas I need custom formula.
Is there any way to add custom function in crystal report and pass it some parameter and then it returns you come data that you show on the report ???
Thanks in advance !

Go to Report --> formula workshop and there go to New and there select custom function
Syntax would be:
Create a function Convert
Function(StringVar value) //this will take the input string
//Here write your logic and return a value.and close the function
Now you have created a custom function.
To use this create a new formula in functions go to custom functions and double click already create function
Convert("11/04/2016"); //close the window and place formula on design and refresh you get required output

Related

Round up double value in jasper report

I have a textfield in jasper report as follows :
<textFieldExpression class="java.lang.Double"><![CDATA[$V{v_vcTotal}]]></textFieldExpression>
I want to round up this value using HALF_UP rounding mode.Can i achieve this in a simple way.Thanks in advance.
EDIT : I dont want to change my java class. Is there anything i can do in jasper jrxml file.
So all credit to #utkarsh their expression is so far the only working one I've seen online that converted my 'double' numbers pulled onto my report, my expression:
$f{balance}
Would produce doubles from a calculated field in my database like "-1365.00000000003"
In the Expression editor (in lieu of changing it in the source tab) I wanted to pull 2 sig figs from the number for looks. I added this expression and I stopped getting "compilation" errors and the wanted results:
new BigDecimal($F{balance}).setScale(2, BigDecimal.ROUND_HALF_DOWN).toString()
Result would be "-1365.00"
From what I've read this is a bit overkill to get the desired result but I am also under a deadline so I will try to optimize some other time.

CRM 2011+ SSRS Report + Currency Formatting

I have created a ssrs report in CRM online using BIDS.
Generated well but those currency field which is negative shows on the report with bracket.
All positive currency fields showing well on the report but negative currency field is showing with bracket like "(value)" on the report.
May do this like "-$value" or something else.
Please help.
You need to change the settings inside the placeholder properties, right click on the field in Design mode and you can choose also the format for negative values
You can try setting the textbox Format property using an explicit format string, something like:
$#,#;-$#,#;$0
To edit a textbox Format property click on the textbox then edit the Format value in the Properties tab:

Return different datatypes crystal formula

I have a requirement where depending on the parameter selected the table field should be displayed as text or date. For eg, if the user selects a true, the OriginDate field which is a datetime type should be displayed as a date in the report else should be displayed as a text. I tried creating a formula an doing something like below, and then placing the formula in the details section of the report but it doesnt work due to different datatypes returned.
if {?Mailmerge}=true then
ToText({Travel.OriginDatetime}, "M/d/yy")
else
{Travel.OriginDatetime}
Is there a way I can accompalish the above requirement so that I do not end up creating 2 reports one with field displayed as text and other as date?
Try creating a formula that returns your field as a string totext({Travel.OriginDateTime},"M/d/yy") and overlay it with the original field {Travel.OriginDateTime} and conditionally suppress them based on the value of {?MailMerge} such that only one shows in any one instance of the report.
If I'm following you, you want to only show M/d/yy when ?MailMerge is true, otherwise yuo want to show the full date?
You can't show different datatypes in the same formula, so just convert them both parts of the conditional statement into strings:
if {?Mailmerge}=true then
ToText({Travel.OriginDatetime}, "M/d/yy") // 8/30/12
else
ToText({Travel.OriginDatetime}, "M/d/yy hh:mm:ss") // 8/30/12 02:06:00
I don't know what exactly your dates look like in the database, but you can use the above as a guideline into formatting your date based on the ?MailMerge parameter.

Suppressing (Hiding) data when exporting in Crystal Reports 2011

I am using the Crystal Reports 2011 designer just to test it out. I need to be able to hide certain components, e.g. a sub-report, when exporting to different formats like Excel or .pdf. I'm guessing this can be achieved through the Suppress field with a formula, but I can't find the right syntax. Needs to be something like this:
If ExportFormat="Excel" then Suppress
Else if ExportFormat="PDF" then Show
It doesn't seem like there is a variable to represent the ExportFormat type when using expressions in Crystal Reports.
It is possible to overcome this problem by setting a parameter programmatically during an export event i.e. create a parameter #ExportFormat and during the export event set this parameter depending on the type of export e.g. if the export taking place is to Excel, set #ExportFormat="Excel". Then the following expression can be used to suppress a control:
{?#ExportFormat}='Excel'
You got it almost completely right:
If ExportFormat='Excel' then TRUE
Else if ExportFormat='PDF' then FALSE
This formula goes into the suppress formula. (You need to click this small button with the "x-2" and pencil on it...)

How to change the SSRS input parameters position in report

My SSRS report contains 7 input parameters and while running my report the size of the parameter(i.e. length) is increasing.
One of my input parameter(drop down list) may contain 100 characters so the size is not constant but i want to place all parameters in 2 lines or 3 lines(in a row).
Now it is coming 2 parameters per a row
Please advice
As gbn indicates, it's not easy to change the built in report server method of presenting the parameters. SSRS likes to always use two parameters per line, presented in the order that they exist in the report (which must match the dependency order.)
So the alternatives that gbn mentions: Both involve building a "Wrapper" application: some custom code or a web page that you can code however you like to get the parameters. Then you call Reporting Services, either in code or by passing a formatted URL with your parameters. The report can be displayed in a frame, new window, or passed as a stream to where ever you'd like.
The URL access is pretty straightforward and reliable: I often use it either by hand (to create "favorites") or in code.
http://msdn.microsoft.com/en-us/library/ms153586.aspx
For what you are looking for, these might be more work than you expected, but they will be extremely flexible for your interface.
Jamie
You can certainly do that, just right click on the RDL file in the solution explorer and select view code. then move the XML tags named <ReportParameter Name="Nameofparameter"> under <ReportParameters> according to where ever you want to position. And then save it. thats it!!!
The report parameters are kind of floating in values of 2, so if u have 4 report parameters then it will be shown as 1,2 next line 3,4. Best of luck!!
Use ASP.NET for the paramaters and a ReportViewer control or URL access to render. Seriously.
I don't know of any option to present parameters any way other then the default
I believe you could try using jQuery. The report parameters are rendered in a table under a div tag with class sqlrv-ParameterContainer. Write a jQuery or JavaScript function that will extract the full innerHTML from this div ie. the table content and then extract the table row information like the <label> or <input> tags.
Create your desired table structure with <table><tr><td>{extracted sections}</td><td></td></tr></table> or leave it to your requirement...
Then just append this new HTML structure in place of the original default structure.
In jQuery it will be like
$(".sqlrv-ParameterContainer").html();
which will give you the entire table structure that comes inside the parameter. Use XML parsing and get the input controls and all. Extract these controls as-is, don't change anything.
$(".sqlrv-ParameterContainer table").remove(); // it will remove the SSRS rendered default table from DOM
$(".sqlrv-ParameterContainer table").appendChild('<table><tr>......</tr></table>'); // Append your custom html structure here....
This was something that came to my mind quickly... I would suggest you test it... :)
This doesn't help the OP with SSRS-2008 but in case it helps others - Microsoft have improved this in SSRS 2016 - parameters can now be easily managed via the GUI in Report Builder / Visual studio:
https://www.intertech.com/ssrs-parameters-2016-update/