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

redhotmustangredhotmustang 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 :
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)

Answers

  • WaldoWaldo Member Posts: 3,412
    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);
    

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • redhotmustangredhotmustang Member Posts: 91
    :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)
  • SavatageSavatage Member Posts: 7,142
    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?
  • redhotmustangredhotmustang Member Posts: 91
    Yes, I do have to code it. :)
    Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)
  • SavatageSavatage Member Posts: 7,142
    Code:
    table.reset;
    table.SETRANGE(yearfield, 2007);

    table.VALIDATE(field,060707D);
    table.MODIFY(TRUE);
    don't know this yearfield type but how about single quotes
    '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;
    
Sign In or Register to comment.