Order date within range then set a value

hairyjimhairyjim Member Posts: 99
edited 2007-05-17 in Navision Attain
HI all,

Im guessing this is pretty straight forward for some of you experienced developers, however I have a headache trying to figure it out.

I want to run a report and for each record it parses I want to check the order date and if it falls within a date range then set a value in another field.

If "Sales Header"."Order Date" 28/04/07..24/05/07 THEN
Period := P5;

Obviously this does not work.

Anyone help?
Give a man a fish and he will eat for a day, teach a man to fish and he will drink beer allday.

Comments

  • BeliasBelias Member Posts: 2,998
    put this code in OnAfterGetRecord() Trigger:
    yourtable.SETFILTER(datefield,'25/11/02..26/12/03');
    if yourtable.find('-') then begin
      repeat
        a := 5;// --> fieldtochange := valueyouwant;
      until yourtable.next = 0;
    end;
    

    explanation: the first line select all the records within the value you want.
    surely you can put a text variable replacing '25/11/02..26/12/03'.
    the second line find the first record within the range you selected and after begins a loop that changes the value of all the fields you want to another value. the loop ends with the "until yourtable.next = 0;" line
    think at this line like an "EOF"
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • krikikriki Member, Moderator Posts: 9,112
    Create a global record on table Date.
    recDate.RESET;
    recDate.SETCURRENTKEY("Period Type","Period Start");
    recDate.SETRANGE("Period Type",recDate."Period Type"::Date);
    recDate.SETRANGE("Period Start","Sales Header"."Order Date");
    recDate.FILTERGROUP(10);
    recDate.SETFILTER("Period Start",'28/04/07..24/05/07'); // or some other filter
    IF recDate.FINDFIRST THEN // or FIND('-')
      Period := P5;
    
    With this you want only the records (there is only 1) of "Order Date" AND the records in your filter. If "Order Date" falls also in the range, I will have 1 record. If it doesn't fall into the range, I WON'T have a record.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • kinekine Member Posts: 12,562
    and if you do not want to filter:
    If ("Sales Header"."Order Date" >= 280407D) and ("Sales Header"."Order Date" <= 240507D) THEN
      Period := P5; 
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • BeliasBelias Member Posts: 2,998
    sorry for my post!!!I saw the big big error I wrote... :oops: the code I wrote is right if putted in onpredataitem, otherwise for each record the process will execute the value change for the whole set of lines filtered
    :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops:
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.