how to validate date in report builder 3.0 - reportbuilder3.0

I have startDate and endDate parameter in my report. I need to validate them with 2 conditions. Below validation code(that not working):
=IIF((Parameters!EndDate.Value < Parameters!StartDate.Value)
AND (Parameters!EndDate.Value >
DateAdd(DateInterval.Month, 1 , Parameters!StartDate.Value)),
"Error", "")
Here first condition only works, second not working. I create TextBox and write it in value expression. What I do wrong?

Related

Acrobat XI - Blanking a field if conditions are met

I have a form my drivers complete where part of the form is related to fueling. There is a possibility of 6 separate fuel stops. Each fuel stop line has input where gallons and cost are also included. By default the Cost and Gallons purchased cost is set to $0.00.
My reason for asking assistance:
Occasionally the drivers will inadvertently clicks into one of the date fields on a fueling line and the date will auto populate with the then current date (which can be changed). Then the rest of that line remains all zeros.
I am trying to figure out a validation script that will put the date field back to NULL preferably (or blank) if the Fuel Purchase Cost is at $0.00 as well as the DEF Purchase Cost is also $0.00. BOTH of these items need to be true. Additionally I am not sure how to keep the user inputted DATE if FUEL_PURCH_STOP_1 is >0 AND DEF_PURCH_STOP_1 >0.
NOTE: Fueling will always span 2-3 days.
My end goal is... If a driver clicks in the date field inadvertently, the current date is auto populated. Then if there is a "0" in the both the FUEL_PURCH_STOP_1 AND DEF_PURCH_STOP_1 fields then remove the date from that line. If either one or both of the two fields have a value >0 then I want to keep the user inputted date in the field.
I tried:
var v1 = +getField("FUEL_PURCH_STOP_1").value;
var v2 = +getField("DEF_PURCH_STOP_1").value;
// Set this field's value
if v1 >0 andalso v2 >0) {
event.valueAsString === "WHAT GOES HERE??";
} else {
event.valueAsString === "";
}
Put the following script into the custom calculation for your date field.
var v1 = this.getField("FUEL_PURCH_STOP_1").value;
var v2 = this.getField("DEF_PURCH_STOP_1").value;
// Set this field's value
if (v1 == 0 && v2 == 0) {
event.target.value = "";
}
Using this script, the date entry will only get modified if both of the other fields are zero. It's left as is when the criteria is not met so you don't actually need the "WHAT GOES HERE??" value.

Optional Multi-Value parameter in BIRT

I have a BIRT report that have 4 optional parameters.
startdate; enddate; stringparam and listparam (multi-value parameter).
I followed "bluish" code on this link How do I set a parameter to a list of values in a BIRT report?
and it works if I give either one or all of the value to the parameter. However, when I leave the parameter blank, I got a blank report (which is incorrect result).
This is my query:
select f1,f2,f3,f4
where f1 >= ? -- startdate parameter
or f2 <= ? -- endate paramter
or f4 = ? -- stringparam
and ( f3 in (''/*?listparam*/) )
I did query on my Oracle db to see what parameter is being passed to my query I got 'NULL' as the VALUE_STRING when I leave the parameters values as blank.
Any help is appreciated.
It sounds like you want to occasionally search for records on one to three of the 4 criteria in the parameters.
There are couple ways to do this:
One way is to use like, and set the default parameter value to % which is the wild card. when the parameter runs it returns all values. Be aware this can be problematic if the fields contain null.
or f4 like ?
So you would need to use something similar to below to return null values.
or (f4 is null
or f4 like ?)
I usually prefer to use "All" as my default parameter value, as you can see in the second "and" we look to see if the parameter value is All, if it is all values for PRODUCTTYPEM1.CATEGORY are returned, if it is anything else it looks for the entered valued in the field PRODUCTTYPEM1.CATEGORY.
where PRODUCTTYPEM1.ACTIVE = 't'
and DEVICE2M1.ISTATUS = 'In Use'
and ( 'All' = ?
or PRODUCTTYPEM1.CATEGORY = ?)
For this to work you will need two parameter entries, the first is for All, the second is for any values other then All.
I only have one Category parameter in the report, the second entry looks at the same parameter a second time if the parameter value is not All
The way this works. (expanded explanation by request)
Opening where statement, and simple second criteria for 'In Use'
where PRODUCTTYPEM1.ACTIVE = 't'
and DEVICE2M1.ISTATUS = 'In Use'
The third criteria is two parts set in parenthesis with an OR statement dividing the two parts
and ( 'All' = ?
or PRODUCTTYPEM1.CATEGORY = ?)
If the value of the parameter is All, then the first part of the statement is met, and the query skips everything thing else in the parenthesis. It is like not have the parameter in your SQL query at all.
If the value of the parameter is NOT all, the first part of the statement is not met so the query looks for the parameter value in field PRODUCTTYPEM1.CATEGORY.
Your final query will probably look something like this, though it is problematic in that we have a Default date of 'All', you probably want to use some kind of date for your default value like Jan 1, 1900.
select f1,f2,f3,f4
where f3 in (''/*?listparam*/)
AND ( 'All' = ?
OR f1 >= ?) -- startdate parameter
AND ( 'All' = ?
OR f2 <= ?) -- endate paramter
AND ( 'All' = ?
OR f4 = ?) -- stringparam

Comparing dates using Dynamic Action on DatePicker Oracle Apex

I have a date picker where the user simply chooses a date then a Dynamic Action is suppose to send an alert if the user clicks tomorrow(sysdate+1).
The Datepicker term is the simple layout.
The Dynamic Action-->
Name: Valid Date
Event: Change
Selection type: Item(s)
Item(s): datepicker_name
Condition: equal to
Value: sysdate+1
When I run the program and click any day on the calendar, no alert comes up. I thought the problem was the format. The Dynamic Action sees the date as "DD/MM/YYYY" while the Datepickers output is "DD-Mon-YY" so it could not compare them. Apples and Oranges. But I played around with the format to make it all the same but still no progress.
Thanks again for your time and help!
As #ScottWe mentions: you're trying to apply PLSQL logic in HTML/javascript. The 'When - Condition' is evaluated at runtime and thus you can't use PLSQL there.
The date arithmetic is a bit annoying in javascript though, so if you're a unfamiliar with it, here is a way you can perform your check (which is, is the entered date tomorrow or not).
Taking my clues from these:
Date difference in Javascript (ignoring time of day)
JavaScript how to get tomorrows date in format dd-mm-yy
Add this function to the page's javascript section for global variables and functions:
function isTomorrow(pDateItem){
function getTomorrow(){
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
return tomorrow;
};
function cutTime(pDate){
return new Date(pDate.getFullYear(), pDate.getMonth(), pDate.getDate());
};
// check if pDateItem leads to a selection
// check if it is a datepicker
// check if a date has been selected
if ( $(pDateItem).length
&& $(pDateItem).data("datepicker")
&& $(pDateItem).datepicker("getDate") !== null
)
{
var tomorrow = getTomorrow();
var check = $(pDateItem).datepicker("getDate");
var one = cutTime(check);
var two = cutTime(tomorrow);
return one.getDate() === two.getDate();
};
return false;
}
Then in your Dynamic action 'When' condition, use a javascript expression with this code:
isTomorrow(this.triggeringElement)
Then the corresponding True Actions will only fire when the date is set to tomorrow.

orbeon Field Validation bugs

I am using a xforms:bind to do field validation for a year field. the code is at below:
<xforms:bind nodeset="instance('application-instance')/academic/cert_ordinary/year" level="year-1" constraint="if (string-length(.) < 1 ) then . = . else . castable as xs:integer and string-length(.) = 4 "/>
while the UI code is below:
<xforms:repeat ref="instance('application-instance')/academic/cert_as" id="cert-as-repeat">
<xforms:input ref="year" incremental="true" class="input_smaller">
<xforms:alert level="year-1">Must be 4 digit year!</xforms:alert>
</xforms:input>
</xforms:repeat>
the validation is working fine, but the problem is, when i add multiple row of data, the validation is not working if i insert some string into the year and then change it to number.
for example, after i put "test" for 3 rows of year, the alert will shown there but then i change it to "2014", the alert for 1 row will still remains there and wont go away.
is this a bug from orbeon? FYI i using the orbeon 4.2.
Thanks
seem like i made a mistake in the if statement
constraint="if (string-length(.) < 1 ) then true() else . castable as xs:integer and string-length(.) = 4"
this shd be the correct if statement.
thanks

How do I dynamically select parameter with crystal report

I have been working on getting a report out for long without success.
I have a report that select based on parameter fields of date and boolean. Currently I have to create 3 reports. One based on dates, one based on the boolean and one based on both.
However, I want my report to be able to select all dates if the user does not input date in the parameter or select all booleans if user does not select one.
Currently I used this
if ({?Start Date} = DateTimeValue('') or {?End Date} =DateTimeValue('')) then
{rectReport.Call date} in DateTimeValue ('1753-01-01 00:00:00') to CurrentDateTime
else
({rectReport.Call date} in {?Start Date} to {?End Date}) and {rectReport.EngineDown} = {?Engine Down}
The basic Idea I am looking for is that the user can decide to select only one parameter instead of the two.
Any help will be highly appreciated.
Thanks,
Bimbo
In Crystal 2008 you have the option of making parameters optional. What you could do is create one report with both parameters and then set both parameters as optional. In your record selection formula you could do something like this:
(if (HasValue({?Startdate}) and HasValue({?Enddate}))
then {table.datefield} in {?Startdate} to {?Enddate}
else {table.datefield} in {defaultstartdate} to {defaultenddate})
and (if HasValue({?BoolParam}) then {table.boolfield} = {?BoolParam}
else {table.boolfield} = {defaultbool})
If you wanted to select ALL tables if the user did not input the parameter, you could just omit the else-statements.
(note: Sorry if that syntax isn't correct (I am just getting back into CR again), but you get the idea.)
EDIT: Since optional parameters aren't available in CR10, couldn't you just use parameter default values for the dates instead? For the boolean, you could just make a parameter with 3 values: true, false, and "all" and then default to the "all" value when running the report.
I don't know your particular situation, but the way we handle this (specifically for Defined Periods vs User-specified-Date-Range) is through being able to set defaults.
Our main environment is BOE XI.
Our parameters might be
ReportPeriod (String Variable)
and
CustomDates (DateTime Range, but will work as two discrete dates)
Example params for ReportPeriod might be
1 Day
7 Days
Last Month
Custom Dates
Formulas are used to calculate date limits that will be used in the record selection. I start with the END DATE, as it is convenient for our period reports.
#EndDate
Select ?ReportPeriod
Case
"1 Day", "7 Days" : CurrentDate
// Conveniently defaults to MIDNIGHT
"Last Month" : Maximum(LastFullMonth)
"CustomDates" : Maximum(?CustomDates)
// Or discrete parameter for end date
default : CurrentDate
#BeginDate
Select ?ReportPeriod
Case
"1 Day" : DateAdd("d", -1, #EndDate)
"7 Days" : DateAdd("d", -7, #EndDate)
"Last Month" : Minimum(LastFullMonth)
"CustomDates" : Minimum(?CustomDates)
// Or discrete parameter for end date
default : DateAdd("d", -1, #EndDate)
And, let me caution against using CurentDateTime unless necessary. Every time you try to step through the report, the selection will have changed: 5:01:10 PM ... 5:01:16 PM ... 5:01:24 PM ...
When publishing a report, we set default date (it doesn't matter what, it's only used for CUSTOM and the customer resets it then), and a default ReportPeriod.
The report can be scheduled periodically (based on ReportPeriod) and it will always run.
If the user wants to do custom dates (historic reporting, etc.), then they can chose that for report period, and then set whatever start and end dates they need.
Helpful?

Resources