Empty parameter in Crystal Reports Not showing NULL - crystal-reports

I have a parameter that prompts the user to enter a value.
If that field is left blank I would think that the parameter would be NULL.
If I run:
isnull({?Param}) then
run this code...
The code does not run
BUT if I run it like:
hasvalue({?Param})
run this code...
The code runs!
Any idea why an empty param field does not return NULL?

From what I know,
hasvalue is used to check if a parameter has a value specified whereas IsNULL is mainly used in conjunction with a database field.
Which is why it may be behaving like that in your case.

Related

Crystal Report: Parameter damages the whole report

While using Crystal Reports I have encountered a strange bug, that repeats itself already with a number of my reports.
I still didn't fully get how I replicate it, but usually it goes as follows:
I add a parameter of any type to an existing report document, however it doesn't appear in a parameter prompt at all.
After I change parameter order in the Parameter Fields Section, my Parameter disappears and instead I see a duplicate of another parameter in a parameter list, and in the "Set Parameter Order"-Window I see this duplicated parameter as [ParameterName, ParameterName]. If I save the document in this moment and try to reopen it, CR crushes.
If I try to load this document in Vstudio with CREngine, the code exits with the message "Access violation".
Here is a pic of what is happening:
The reason you are not being prompted for the new "test" parameter is that it is not used by the report for anything.
The rest of the behavior is indeed strange. Consider removing the '#' character from the name of the first parameter to see if that fixes it.
If some of those parameters are from a stored procedure, perhaps your report is simply out of sync with the data source. Do Database, Verify Database...

how to disable 2nd parameter we select 1st parameter in crystal reports

Please guide how to do this requirement.
I Have a report having 2 command level parameters a and b.
If they select any of the one parameter then other one should be disabled/should not ask any value to enter /should not take any value .
Please suggest how to do
Command don't support optional parameters. Moreover, you can't disable or hide a parameter based on another parameter's value.
Your best option is to create a parameter that has a default value that will be 'ignored' by the query.
For example, given this Access command:
SELECT *
FROM customer
WHERE region='{?Region}'
with this parameter:
you will note that the parameter's Optional Prompt setting is false (and not editable):
Instead, you will need to a default, something like 'ALL' (or -1, in the case of a numeric value):
Modify the command accordingly:
SELECT *
FROM customer
WHERE ( '{?Region}'='ALL' OR region='{?Region}' )
This should be a feature of the user interface. You can implement it if you write your own software. The only viewer , which MIGHT be able to do this is R-Tag (www.r-tag.com). But even it will need to do some workaround ( if can do it at all). This behavior is very unique. Why would you need to have it ?

Enter a query in a default value expression

In Jasperreports I would like to enter a Default Value Expression to a Parameter as a Query string to be able to dynamically provide the user with a default value that is correct, but not force him to choose it.
Is there anyway?
I guess the result should look something like this (even though it doesn't work):
I am using this for a form with a single-value selection method (the user can write which ever number he/she wants but I want the default value to be selected from the database).
Here's how I handle this:
The user selects a value from an input control (in my example, I will call it $P{time_toggle}). Then, I have another parameter ($P{time_constraint}) that takes the user input from $P{time_toggle} and decides what SQL string to inject into the main query based on it. The default value expression for $P{time_constraint} looks like:
$P{time_toggle} == "rolling_quarter" ? "..." : (
$P{time_toggle} == "rolling_30_days" ? "..." : (...
)
)
Then, in my main report query I reference $P{time_constraint}:
SELECT * FROM tblTable WHERE $P!{time_constraint}
To set a default time period, I set the default value expression for $P{time_toggle} to my desired default.

Get statuscode text in C#

I'm using a plugin and want to perform an action based on the records statuscode value. I've seen online that you can use entity.FormattedValues["statuscode"] to get values from option sets but when try it I get an error saying "The given key was not present in the dictionary".
I know this can happen when the plugin cant find the change for the field you're looking for, but i've already checked that this does exist using entity.Contains("statuscode") and it passes by that fine but still hits this error.
Can anyone help me figure out why its failing?
Thanks
I've not seen the entity.FormattedValues before.
I usually use the entity.Attributes, e.g. entity.Attributes["statuscode"].
MSDN
Edit
Crm wraps many of the values in objects which hold additional information, in this case statuscode uses the OptionSetValue, so to get the value you need to:
((OptionSetValue)entity.Attributes["statuscode"]).Value
This will return a number, as this is the underlying value in Crm.
If you open up the customisation options in Crm, you will usually (some system fields are locked down) be able to see the label and value for each option.
If you need the label, you could either do some hardcoding based on the information in Crm.
Or you could retrieve it from the metadata services as described here.
To avoid your error, you need to check the collection you wish to use (rather than the Attributes collection):
if (entity.FormattedValues.Contains("statuscode")){
var myStatusCode = entity.FormattedValues["statuscode"];
}
However although the SDK fails to confirm this, I suspect that FormattedValues are only ever present for numeric or currency attributes. (Part-speculation on my part though).
entity.FormattedValues work only for string display value.
For example you have an optionset with display names as 1, 2, 3,
The above statement do not recognize these values because those are integers. If You have seen the exact defintion of formatted values in the below link
http://msdn.microsoft.com/en-in/library/microsoft.xrm.sdk.formattedvaluecollection.aspx
you will find this statement is valid for only string display values. If you try to use this statement with Integer values it will throw key not found in dictionary exception.
So try to avoid this statement for retrieving integer display name optionset in your code.
Try this
string Title = (bool)entity.Attributes.Contains("title") ? entity.FormattedValues["title"].ToString() : "";
When you are talking about Option set, you have value and label. What this will give you is the label. '?' will make sure that the null value is never passed.

How does one pass null values to optional parameters in a Business Objects report using the Business Objects SDK?

I am building a web front end for accessing Business Objects reports using the Business Objects SDK for .NET. I have been able to hack my way through 95% of the business requirements with the sparse documentation and forum posts available online for the topic. My final roadblock centers on working with parameterized reports. Our business has situations in which a report has two parameters and the end user is only requried to populate one of them. It's easy enough to collect and cleanse this data, but no matter how I try to pass the null valued parameter to the reports, I get no data back. If both parameters are populated I DO get the expected data. When stepping through the code in Visual Studio I see that whenever BusinessObjects returns a null valued parameter it displays as an empty string (""). I have tried passing this as a parameter value and have also tried assigning the parameter a value of null. Neither of these options returns results once the report is scheduled and run. I have an example of my parameter assignment code below using each of the approaches that I've taken (We need to check for a string valued "null" as the user's have requested the ability to type "null" and have that passed to the report). None of these produce a report that contains data.
sVal.Value = param.ParameterValue != "null" ? param.ParameterValue : String.Empty;
sVal.Value = param.ParameterValue != "null" ? param.ParameterValue : "";
sVal.Value = param.ParameterValue != "null" ? param.ParameterValue : null;
Is there a specific value that the Enterprise Server uses to indicate null, such as dates are required to be wrapped in Date()?
Edit: The functionality I need to duplicate as seen in InfoView:
In Web Intelligence, by default all prompts are required and you must provide a value for it via the SDK. As of BusinessObjects XI R3 it is possible to actually configure the prompt in the report to be optional. This configuration is done by the report writer. When the prompt is optional then you can opt to not set the prompt value when working with the SDK.
An alternate way to have an optional prompt is to make the prompt "matches pattern" or if it is a date, figure out a default value. When the prompt is meant to be optional and is "in list" then you can set the value to be "%" which, while for a date, set the default value.