SETFILTER problem
mkpjsr
Member Posts: 587
Hi all,
I want to filter records from Sales Invoice Line table based on the month from Posting Date field with the value comming from request variable, so i have written the code.
Smonth ->Integer [used for receiving month value from request form]
"Sales Invoice Line".SETFILTER(DATE2DMY("Sales Invoice Line"."Posting Date",2),'%1',SMonth);
but its not allowing to use DATE2DMY function inside the SETFILTER function.
how can i achieve this.
I want to filter records from Sales Invoice Line table based on the month from Posting Date field with the value comming from request variable, so i have written the code.
Smonth ->Integer [used for receiving month value from request form]
"Sales Invoice Line".SETFILTER(DATE2DMY("Sales Invoice Line"."Posting Date",2),'%1',SMonth);
but its not allowing to use DATE2DMY function inside the SETFILTER function.
how can i achieve this.
0
Answers
-
mkpjsr wrote:"Sales Invoice Line".SETFILTER(DATE2DMY("Sales Invoice Line"."Posting Date",2),'%1',SMonth);
You cannot use that.
SETFILTER is followed by the field on which you want to filter.
You will have to use variables and get the Starting date of the month and the ending date of the month.
Then do a SETRANGE("Posting Date",StartMonthDate,EndMonthDate) or the SETFILTER("Posting Date",'%1..%2,'StartMonthDate,EndMonthDate).
Have you read the documentation / help to figure out the syntax of the commands?0 -
kapamarou wrote:Then do a SETRANGE("Posting Date",StartMonthDate,EndMonthDate) or the SETFILTER("Posting Date",'%1..%2,'StartMonthDate,EndMonthDate).
That will not fullful to requirment.
he wants entries with specific month filter either year would have 2001,2002,2003......so.
I think you(mkpjsr) have to extract each entry for calculate month and then use SETRANGE.
but it will create problem when you want to set filter on ONPREDATAITEM trigger.
let see more reply...0 -
i think so...
in this case it can be best.0 -
Have in mind you couold use the CALCDATE function; e.g. like this:
SMonth := <VariableInput>; StartDate := DMY2DATE(1, SMonth, DATE2DMY(WORKDATE, 3)); // first day of SMonth EndDate := CALCDATE('+1<M>-1<D>', StartDate); // last day of SMonth SalesInvoiceLine.SETRANGE("Posting Date", StartDate, EndDate);Jörg A. Stryk (MVP - Dynamics NAV)
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool0 -
There's no need for additional variables, data type conversion or any other fancy programming. CALCDATE has what you need. Use CM in your CALCDATE, which stands for Current Month. For the first of the month use -CM, for the last of the month use +CM.
Create a new blank form, put a button on it, and in the OnPush of that button, paste this code:MESSAGE(format(CALCDATE('<-CM>',TODAY)) + '\' + format(CALCDATE('<+CM>',TODAY)));The angle brackets are to keep translation issues out of the picture.
For putting a proper date filter into your SETFILTER, you're going to have to think about that. Think about what a proper date filter looks like, and make sure that the value that you put in there is a proper date filter. DATE2DMY returns an integer, and an integer is NOT a proper value for a date filter.0 -
DenSter wrote:There's no need for additional variables, data type conversion or any other fancy programming. CALCDATE has what you need. Use CM in your CALCDATE, which stands for Current Month. For the first of the month use -CM, for the last of the month use +CM.
Create a new blank form, put a button on it, and in the OnPush of that button, paste this code:MESSAGE(format(CALCDATE('<-CM>',TODAY)) + '\' + format(CALCDATE('<+CM>',TODAY)));The angle brackets are to keep translation issues out of the picture.
For putting a proper date filter into your SETFILTER, you're going to have to think about that. Think about what a proper date filter looks like, and make sure that the value that you put in there is a proper date filter. DATE2DMY returns an integer, and an integer is NOT a proper value for a date filter.
but in my case month is not always the current month, then how to do0 -
Create a test form, with the button, and put the code in the button. Then create a date variable (call it "MyDate"), add a textbox to the form, and set the text box's SourceExpr to MyDate. Change the code that I gave you to use MyDate instead of TODAY. Enter any date in the textbox and see what happens.
Try it, and see.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 323 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
