Filter Date for Reporting - dynamics-crm

I am currently working with reports in Navision by a "book sales" currently use 2 variables "Date" one for the start and one for the end of the filter, but I wonder if you can only use a single variable where the user directly enter "month" and "year". Thank You!

If you are setting the filter with SETRANGE you need two values. But if you use SETFILTER you can use a string with a date filter like this:
010115..103115
p1..p3
and the just:
DateField.SETFILTER(filterstring);

Yes, when the user put the month and year data you by code transform this info in date values example:
Variables from and to = date
from := DMY2DATE(1, Month, Year);
EVALUATE(to, FORMAT(CALCDATE('+1M', Desde) -1));
YourTable.SETRANGE("Posting Date", from, to);

Related

Lotus sorting view on orderdate does not work properly

I have created a view in which I also have a column which holds dates. This column can be sorted on ascending and descending. This is my column properties value:
But the problem is that the view does not sort the dates properly:
And here a screenshot of the orderdate field itself:
And here screenshot of the document with the orderdate that is out of order in the view:
Update
Some documents had the orderdate as text instead of date.. I create these documents through a java agent. The field orderdate I fill in like this:
SimpleDateFormat formatterDatumForField=new SimpleDateFormat("dd-MM-yyyy");
docOrder.replaceItemValue("Orderdatum",formatterDatumForField.format(currentDateForField));
But it is saved as text instead of date. Anyone knows why?
Problem was that orderdate field was set by a backend agent and this field was set with a string.
I know saved the current time as a DateTime object and now it works:
DateTime timenow = session.createDateTime("Today");
timenow.setNow();
docOrder.replaceItemValue("Orderdatum", timenow);
It's not clear to me why it's not working for you, but you can brute force it with something like this in the column formula
dateForSure := #TextToTime(OrderDatum);
#Text(#Year(dateForSure)) + "-" + #Text(#Month(dateForSure)) + "-" + #Text(#Day(dateForSure));
Also: your Java code saves a text value because the format() method of SimpleDateFormat returns a StringBuffer. The ReplaceItemValue method generates a text item when its input is a String or StringBuffer. Assuming your form defines OrderDatum as a Time/Date field, you can call Document.ComputeWithForm in your code to force it to convert the text item to a Time/Date. Another method - probably preferable given the potential side-effects of calling ComputeWithForm would be to create a DateTime object in your Java code and pass it to the ReplaceItemValue method instead.
It's because formatterDatumForField.format(currentDateForField) returns a String instead of a date/time value. Assuming that currentDateForField is a date/time value, you should change
SimpleDateFormat formatterDatumForField=new SimpleDateFormat("dd-MM-yyyy");
docOrder.replaceItemValue("Orderdatum",formatterDatumForField.format(currentDateForField));
to
docOrder.replaceItemValue("Orderdatum",currentDateForField);

Retrieve database records between two weekdays

I have several records in my database, the table has a column named "weekday" where I store a weekday like "mon" or "fri". Now from the frontend when a user does search the parameters posted to the server are startday and endDay.
Now I would like to retrieve all records between startDay and endDay. We can assume startDay is "mon" and endDay is "sun". I do not currently know how to do this.
Create another table with the names of the days and their corresponding number. Then you'd just need to join up your current table with the days table by name, and then use the numbers in that table to do your queries.
Not exactly practical, but it is possible to convert sun,mon,tue to numbers using MySQL.
Setup a static year and week number like 201610 for the 10th week of this year, then use a combination of DATE_FORMAT with STR_TO_DATE:
DATE_FORMAT(STR_TO_DATE('201610 mon', '%X%V %a'), '%w')
DATE_FORMAT(STR_TO_DATE('201610 sun', '%X%V %a'), '%w')
DATE_FORMAT(STR_TO_DATE('201610 tue', '%X%V %a'), '%w')
These 3 statements will evaluate to 0,1,2 respectively.
The main thing this is doing is converting the %a format (Sun-Sat) to the %w format (0-6)
well i don't know the architecture of your application as i think storing and querying a week day string is not appropriate, but i can tell you a work around this.
make a helper function which return you an array of weekdays in the range i-e
function getWeekDaysArray($startWeekDay, $endWeekDay) {
returns $daysArray['mon','tue','wed'];
}
$daysRangeArray = getWeekDaysArray('mon', 'wed');
now with this array you can query in table
DB::table('TableName')->whereIn('week_day', $daysRangeArray)->get();
Hope this help

Unable to extract Model Data Using created_at in rails 2 application

#versions = Version.find_all_by_created_at(2015-05-07)
#versions = []
datatype for created_at(datetime)
Please i want extract data by passing only date to a model .
I think it is simple
If you want to do it for the current date then you can just use Date.today
Version.where(created_at: Date.today.beginning_of_day..Date.today.end_of_day)
Otherwise as #davidesantangelo has mentioned that is fine, except using parsed "date" variable, you can use "date.beginning_of_day"
e.g.
selectDate = Date.parse('2015-05-07')
Version.where(created_at: selectDate.beginning_of_day..selectDate.end_of_day)
That will form query like this:
SELECT "versions".* FROM "versions"
WHERE ("versions"."created_at"
BETWEEN '2015-04-28 00:00:00.000000' AND '2015-04-28 23:59:59.999999')
And without "beginning_of_day" it will have query like
SELECT "users".* FROM "users"
WHERE ("users"."created_at"
BETWEEN '2015-04-28' AND '2015-04-28 23:59:59.999999')
So I would prefer it with beginning_of_day.
try this
date = Date.parse('2015-05-07')
and then
Version.where("created_at <= ? AND created_at >= ?", date + 1, date - 1)
Created at is a datetime so it would be very specific. You need to search within the same day
date = Date.parse('2015-05-07')
Version.where(created_at: date..date.end_of_day)

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?

Get the the most recent and the one before the most recent item

I have a table with many anniversaries : Date + Name.
I want to display the next anniversary and the one after with Linq.
How can i build the query ?
I use EF
Thanks
John
Just order by date and then use the .Take(n) functionality
Example with a list of some objects assuming you want to order by Date then Name:
List<Anniversaries> annivDates = GetAnnivDates();
List<Anniversaries> recentAnniv = annivDates.OrderBy(d => d.Date).ThenBy(d => d.Name).Take(2).ToList();
If the anniversaries are stored in regular DateTime structs, they may have the 'wrong' year set (i.e. wedding or birth year). I suggest writing a function which calculates the next date for an anniversary (based on the current day) like:
static DateTime CalcNext(DateTime anniversary) {
DateTime newDate = new DateTime(DateTime.Now.Year, anniversary.Month, anniversary.Day);
if (newDate < DateTime.Now.Date)
newDate = newDate.AddYear(1);
return newDate;
}
Then you proceed with sorting the dates and taking the first two values like described in the other postings:
(from e in anniversaries orderby CalcNext(e.Date) select e).Take(2)

Resources