(Dev) Use a report to change the date on a table

redhotmustang
Member Posts: 91
Hi there,
I'm beginning to work as a Navision Developer.
I just finish my classroom training, but haven't yet taken my exams.
There is plenty of work here and my colleagues are already giving me stuff to work on. Therefore, please excuse my poor knowledge on developing in C/AL.
They asked me to create a routine that would change the date on a field of a table.
I thought I could use a processing only report to go to every record of that table and change that field's date. I need to change it to 06-07-2007.
I created a new data item for that table. And placed this code on the onAfterGetRecord() trigger :
Who do I change this to put the date I want (06-07-2007)?
Navision does not accept this kind of data, saying "one of the operators contains an invalid data type".
I understand that 06-07-2007 should be of the date data type.
How can I do this?
Thanks and sorry for my ignorence. ](*,)
Regards.
EDIT: should it be like:
I'm beginning to work as a Navision Developer.
I just finish my classroom training, but haven't yet taken my exams.
There is plenty of work here and my colleagues are already giving me stuff to work on. Therefore, please excuse my poor knowledge on developing in C/AL.
They asked me to create a routine that would change the date on a field of a table.
I thought I could use a processing only report to go to every record of that table and change that field's date. I need to change it to 06-07-2007.
I created a new data item for that table. And placed this code on the onAfterGetRecord() trigger :
tablename.field := today
Who do I change this to put the date I want (06-07-2007)?
Navision does not accept this kind of data, saying "one of the operators contains an invalid data type".
I understand that 06-07-2007 should be of the date data type.
How can I do this?
Thanks and sorry for my ignorence. ](*,)
Regards.
EDIT: should it be like:
tablename.field := 060707D
Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)
0
Answers
-
Sell, in the OnAfterGetRecord is correct.
If you would like to make it the same date as today, I would write:tablename.VALIDATE(field, TODAY); tablename.MODIFY(TRUE);
The "VALIDATE" makes sure that your code behind the OnValidate trigger is executed as well.
It's obvious that the "field" if of the datatype TODAY.
If you want to change your date to 06/07/07, then you could write:tablename.VALIDATE(field, 060707D); tablename.MODIFY(TRUE);
0 -
:P Thanks!
This really helped. I bought "Programming Microsoft Dynamics NAV" by David Studebaker, but I haven't had time to study it yet. I wish I had more time.
Another question related to the date data type:
They also asked me to only change the date field (to 06-07-07) of the records that had the year of 2007 on another field of the same table.
I used this, but then again had the same problem: 'invalid data type".
(If I change the yearfield to integer and remove the quotes from 2007, it works).table.reset; table.SETRANGE(yearfield, 2007); table.VALIDATE(field,060707D); table.MODIFY(TRUE);
What do I do to be able to use 2007 as the year?
Thanks!
Is the answer 2007Y, table.SETRANGE(yearfield, 2007D);? yearfield is a date data type field.
If you explain how the date data type works that would be nice. I don't understand the date format 010101D <-- this I get, 01/01/01, D = stands for day.Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)0 -
If it's a report - you can simply set the filter on the Req Filter Form.
Add the field you want to filter and put 010107..123107
Or does it have to be with code?0 -
Yes, I do have to code it.Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)0
-
Code:
table.reset;
table.SETRANGE(yearfield, 2007);
table.VALIDATE(field,060707D);
table.MODIFY(TRUE);
'2007'
Nav you will find usually has several ways of achiving a goal. which I like.
You could also..If Yearfield <> '2007' Then Begin CurrReport.Skip; End Else Begin VALIDATE(field,060707D); MODIFY(TRUE); END;
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
- 320 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