Filtering of variable

kolaboykolaboy Member Posts: 446
Hi;
I have a report which is displaying figures from a global variable of decimal datatype. I want to filter this variable to give say only value less than two. Say hardcoding the variable to give only values less than two.
MonOwed:=  NofMonths - NumPayments;

The above line of code is calculating MonOwed, where NofMonths and NumPayments are calculated and iare also a variables. I created a request form with MonOwed as the sourceExp. I want to put say 2 in the textbox and and it should give me only MonOwed:= 2. If i also say >6, i should be about to have all MonOwed > 6 and so on. This is the filter i want. If this filter is done, it should add up the MonOwed.But its not working that way for me.

Any idea please?

Comments

  • kinekine Member Posts: 12,562
    May be I didn't catch your idea, but if you want to filter something, you need to put it into some table (e.g. temporary) and than it is not problem to filter it as you wish...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • kolaboykolaboy Member Posts: 446
    Hi Kine,
    how can i do this. You idea sound good, but i don't know how do go about it. Can you explain it to me with sample code to achieve this please.
    Thanks
  • kinekine Member Posts: 12,562
    I will describe it in ideas, if you do not know how to make the code for it, I recommend to read some books (manuals), do some small things... but I think that you will be able to think it out yourself.

    1) Create variable of type record, for some table which have fields of type you need to sort. You can create your own or use some existing

    2) In loop, where you are calculating the values, insert new record for each "variable" you want to filter with all needed values filled in into the table (record type variable) from step 1

    3) Set appropriate filters to the fields you want to filter on.

    4) In a loop read all records from the table - you will "see" only records for "variables" you want...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • webweb Member Posts: 102
    thanks kine. I also have similar problem and i will be grateful if you can give us a sample code to achieve this. We need help from people like you. Thanks
  • EugeneEugene Member Posts: 309
    try in the OnAfterGetRecord trigger the following code:
    IF MonOwed<=6 then CurrReport.SKIP
    

    it will skip the dataitem line and will move to the next one
  • kolaboykolaboy Member Posts: 446
    IF MonOwed<=6 then CurrReport.SKIP
    
    i have used the above code but not working.
    here is my code

    IF MonOwed <= 6.00 THEN BEGIN
    CurrReport.SKIP;
    END ELSE BEGIN
    GArreasVarTotal+=ArreasVarTotal;
    GTotCustBal1+=TotCustBal1;
    TotalmonthsOwed += MonOwed;
    MESSAGE('The value of %1 is %2','TotalmonthsOwed',TotalmonthsOwed)
    END;
    

    Anything the problem?
    [/code]
  • EugeneEugene Member Posts: 309
    where do you assign a new value to your variable:
    MonOwed:=  NofMonths - NumPayments;
    

    also where (in what dataitem and what trigger) did you put the CurrReport.SKIP code ?

    would be great if you post a dataitems layout of your report
  • kolaboykolaboy Member Posts: 446
    I just created MonOwed as a variable to store the Months owned values and the CurrReport.SKIP is place in the OnAfterGetRecord of the Cust. Ledger Entry Table.
    I need to be able to filter by MonOwed.
    I have two dataItems; Customer dataitem and Cust. Ledger Entry which is indented and linked by customers no. and dates.
    Any Idea please?
  • EugeneEugene Member Posts: 309
    if i understood rigfht MonOwed is a parameter to set in the options preview form and then you want to compare it with (NofMonths - NumPayments)

    so probably your code in the onaftergetrecord trigger should look like this:
    IF MonOwed <> NofMonths - NumPayments THEN
      CurrReport.SKIP
    
  • kolaboykolaboy Member Posts: 446
    MonOwed is variable created ad decimal datatype which is the difference of NofMonths - NumPayments and i need to be able to filter by MonOwed.
    I used request form so as to filter by MonOwed but its not working. I used the code below but not working.
    IF MonOwed <= 6.00 THEN 
    CurrReport.SKIP;
    

    what i am not doing correctly?
    Thanks
  • SavatageSavatage Member Posts: 7,142
    kolaboy wrote:
    MonOwed is variable created ad decimal datatype which is the difference of NofMonths - NumPayments and i need to be able to filter by MonOwed.
    I used request form so as to filter by MonOwed but its not working. I used the code below but not working.
    IF MonOwed <= 6.00 THEN 
    CurrReport.SKIP;
    

    what i am not doing correctly?
    Thanks

    Which one is it??
    1)Are you setting the Value In the Request Form
    OR
    2)is it the different of Months & Payments
    OR
    3)is it hardcoded to 6?

    It can't be all three?

    I can see somtheing like
    MonOwed := MoOFMonth - NumOfPayments;

    if MonOwed <= "VariableSetOnRequestForm"
    then CurrReport.Skip;

    Hardcoding a 6 or whatever does not allow for changes.
  • kolaboykolaboy Member Posts: 446
    I used use both the request form and the hardcoding but none of the works.
    I succeeded with the hardcoding and it is skipping what is not needed, but the total at the bottom is not added the filtered value but it is adding everything.
    here is the code:
    IF MonOwed >=13.00 THEN BEGIN
    CurrReport.SKIP;
    END;
    TotalmonthsOwed += MonOwed;
    

    This is what is not totaling correctly:
    TotalmonthsOwed += MonOwed;
    
    Any other ideas?
    Thanks
  • BBlueBBlue Member Posts: 90
    Just a small thought: Do you use the report for more than 1 customer?
    In this case do you clear the NofMonths and NumPayments variables (MonOwed = NofMonths - NumPayments) for each new customer? That is to say, on the OnAfterGetRecord of Customer dataitem did you put...
    NofMonths := 0;
    NumPayments := 0;
    
    //Bogdan
  • David_SingletonDavid_Singleton Member Posts: 5,479
    I think that its necessary to solve the BUSINESS requirement, not try to hack code.
    David Singleton
  • kolaboykolaboy Member Posts: 446
    Yes i am doing it for each customer. I have not set those initialisations to zero. How do you think it will help.
    Thanks
Sign In or Register to comment.