1

I have a view selection formula:

Var :=@If(@IsAvailable(ENVIADO); @If(ENVIADO != "Sim"; "Valido";"");"Valido");
SELECT (Form="Documento"&@Date(Notes_data)>@Date(2013;3;31)&Emissor!=""&DocApagado="Não"&Estado="Definitivo"&@IsUnavailable($Conflict)) & Var = "Valido"

And I want it to select all documents from the past 7 days.excluding "today".

torrential coding
  • 1,755
  • 2
  • 24
  • 34
PedroPinto
  • 21
  • 1
  • 1
  • 7

3 Answers3

1

Firstly, nobody will thank you for putting dates into a selection formula, as the view index has to be recreated every time the view is opened. It is much better to have a field in each document that will be either "y" or "n" depending on whether you want the document in this view. Then run an agent nightly to check which documents meet the criteria, and set the flag accordingly.

BUT, if you HAVE to have dates in your selection formula here's a suggestion (also, it helps to format the formula nicely to make it more readable). I'm presuming that "Notes_data" is the relevant field.:

Var :=@If(@IsAvailable(ENVIADO); @If(ENVIADO != "Sim"; "Valido";"");"Valido");
SELECT (
Form="Documento" &
@Date(Notes_data) < @Today &
@Date(Notes_data) > @Adjust(@Today(0;-8;0;0;0;0)) &
Emissor!="" &
DocApagado="Não" &
Estado="Definitivo" &
@IsUnavailable($Conflict)
) & 
Var = "Valido"

But, as I said before. Please don't do it this way.

Phil M Jones
  • 825
  • 5
  • 15
  • Hi!! tks!! Yes... "notes_Data" is the relevant field but... "Passing arguments to a non-function or to an @Function that doesn´t requires arguments ';' " – PedroPinto Apr 19 '13 at 16:51
  • 1
    No please.. Really don't do it that way. You can cause numerous issues using date related \@Functions in views ( \@Today, \@Tomorrow, \@Now, etc). – Simon O'Doherty Apr 19 '13 at 17:11
  • 1
    You can follow Phil's suggestion which is to create an agent that runs every night at midnight. Here's an example: FIELD Last7Days := \@If(\@Date(Notes_data) < \@Today & \@Date(Notes_data) > \@Adjust(\@Today(0;-8;0;0;0;0) ; "Y"; "N"). If you do this, you can use the expression Last7Days = "Y" in your selection formula. The avoids the big performance hit that your server will take if you use @Today in a selection formula. – Richard Schwartz Apr 19 '13 at 17:46
  • 2
    Or create a folder and a simple FT-Search query agent that selects the documents you need and puts them in the folder. No need to modify documents unnecessarily. – D.Bugger Apr 20 '13 at 14:25
1

My approach to this is to use the @SetViewInfo([SETVIEWFILTER]; in the postOpen and queryClose events of the view. To do this, change your selection formula to:

Var := @If(@IsAvailable(ENVIADO); @If(ENVIADO != "Sim"; "Valido";"");"Valido");
SELECT (Form="Documento" & Emissor!="" & DocApagado="Não" &
        Estado="Definitivo" & @IsUnavailable($Conflict) ) & 
       Var = "Valido"

Next add a column at the beginning of the view which is sorted and categorized. Give it this formula:

out := "";
@For(i:=1; i<7; i:=i+1;
    wrkDt := @Adjust(Notes_Data; 0; 0; (i*-1); 0; 0;0);
    tmp1 := @Text(@Year(@Date(wrkDt))) +
        "-" + @Right("00" + @Text(@Month(wrkDt));2) +
        "-" + @Right("00" + @Text(@Day(wrkDt));2);
    out := @Trim(out : tmp1)
);
out

This will result in every document you want displayed on a given date appearing in the seven categories of the view for each date you would like it to appear.

If this is a web application you can then use RestrictToCategory setting to display just today's documents. If this is a Notes Client application, change the PostOpen event of the View to run formula code and set it to:view to

tmp1 := @Text(@Year(@Today)) +
        "-" + @Right("00" + @Text(@Month(@Today));2) +
        "-" + @Right("00" + @Text(@Day(@Today));2);
@SetViewInfo([SetViewFilter]; tmp1);

You will now see just the docs for today when you open the view. AND it will not constantly need to be refreshed.

NOTE: I use this text format to assure that this will work the same for any local date display format even when the server and the client use different formats.

One caveat... The SetViewInfo stays in effect for ALL views in the current database, so you should add to all the PostOpen events of views other than this one a formula which clears the value:

@SetViewInfo([SetViewFilter]; "");

Happy coding

/Newbs

Newbs
  • 1,632
  • 11
  • 16
0

days:=(@Today - @created)/86400;

It will return the number of days from the today and the creation date of the document. You can give the condition depends your requirement.

Ramkumar
  • 874
  • 11
  • 27
  • Ramkumar... i put this code on a new column right? after this... how can filter this new column? – PedroPinto Apr 29 '13 at 11:46
  • You join this code into your view selection formula. In above code, days will return the number of days from today and created date. You can use the days as of your requirements. – Ramkumar May 02 '13 at 04:00