Date Filter in a codeunit

iqbalmadiqbalmad Member Posts: 179
edited 2009-01-20 in Navision Attain
Hi,

I have a "Date Filter" defined as Flowfilter in a table

Does this line of code work in a codeunit???
SETRANGE("Date Filter",ldateFirstDate,ReportingDate);

if i do the same thing in a report, it works fine..

can any1 tell me y it doesnt work in a codeunit??

Comments

  • kapamaroukapamarou Member Posts: 1,152
    Can you show us the code?
    Have you debugged your code to see the values?

    It should work...
  • iqbalmadiqbalmad Member Posts: 179
    in my table > i have a field Forecast which is a sum of Total Costin Job Budget Entry.

    in the codeunit, i use the Date Filter which is a flowfilter, to calculate the sum between two dates.

    Below are the codes..


    WITH lGenProdPostGrp DO BEGIN
    SETRANGE("Job Filter",pJob."No.");

    //first date of the month
    lintMonth := DATE2DMY(ReportingDate ,2);
    lintYear := DATE2DMY(ReportingDate ,3);
    IF lintMonth < 10 THEN
    ltxtMonth := '0'+FORMAT(lintMonth)
    ELSE
    ltxtMonth := FORMAT(lintMonth);
    EVALUATE(ldateFirstDate,'01'+ ltxtMonth + FORMAT(lintYear));

    IF ReportingDate <> 0D THEN
    SETRANGE("Date Filter",ldateFirstDate,ReportingDate);
  • kapamaroukapamarou Member Posts: 1,152
    You can get the first date of the month by using:

    MyDate := CALCDATE('-CM',ReportingDate);

    Does your filter get the values you specify?
    Have you included the date field in the formula of the flowfield?

    Also do you call CALCFIELDS after applying the filters?
  • garakgarak Member Posts: 3,263
    Use for the calculating of the first day of month the calcdate function
    MyDateFilter := calcdate('<-CM>',ReportingDate);
    

    use here the '<' and the '>'. So your source works also on other systems with other languages. Because the '<' '>' defines the NAV Standard source.

    Your FlowField would be calculated, if you calcfield is also after setting the filter.
    YourTable.setrange("Date Filter",MyDateFilter); //or setrange("Date Filter",calcdate('<-CM>',ReportingDate));
    if YourTable.find('-') then
      YourTable.calcfields(YourFlowField);
    

    Regards
    Do you make it right, it works too!
  • iqbalmadiqbalmad Member Posts: 179
    i jus changed my codes to


    WITH lGenProdPostGrp DO BEGIN
    SETRANGE("Job Filter",pJob."No.");

    IF ReportingDate <> 0D THEN
    SETRANGE("Date Filter",CALCDATE('<-CM>',ReportingDate),ReportingDate);


    and miraculously :-) it worked..

    Thanks guys
Sign In or Register to comment.