LS Evaluate problems

Hi!

I’ve searched the forum for similar problems and found quite a bit on the evaluate + @dbcolumn and the LS equivelant of @Max but still can’t get my code to work.

I’m trying to do a counter in the Querysave event that sets a unique number in the Phone-field, but need to do it in LS since the Continue flag doesn’t exist in Formula and I have to be able to halt the save if some conditions aren’t met.

The Formula code that works is as follows:


@If(!@IsNewDoc;

"";

@Do(

NL := @DbColumn(“Notes”:“NoCache”;“”:“”;“($Num)”;1);

NLMax := @Max(@ToNumber(NL));

NT:=NLMax+1;

@SetField(“Phone”;@Text(NT))))


The LS code that don’t is:


Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim NL As Variant

Dim NLMax As Integer

Dim NT As Integer

NL = Evaluate({@DbColumn(“”;“”:“”;“($Num)”;1)})

NLMax = Evaluate({@Max(@Tonumber(NL))})

NT = NLMax+1

Call source.fieldSetText (“Phone”,Cstr(NT))

End Sub


All I want to do is to check for the highest number in a column and set a field to the next number. I haven’t gotten to the @isnewdoc check yet since I got stuck on Evaluate.

Any help is appreciated!

Regards

Frank

Subject: LS Evaluate problems

NL := @DbColumn(“Notes”:“NoCache”;“”:“”;“($Num)”;1);NLMax := @Max(@ToNumber(NL));

NT:=NLMax+1;

You could use:

dim session as new notessession

Dim db as notesdatabase

Dim view As NotesView

dim number as double

Set db = session.CurrentDatabase

Set view = db.GetView(“($Num)”)

number = view.AllEntries.Count

number=number+1

Subject: LS Evaluate problems

Hi

NL = Evaluate({@DbColumn(“”;“”:“”;“($Num)”;1)})

NLMax = Evaluate({@Max(@Tonumber(NL))})

I’m quite sure that your formula doesn’t know what NL is.

Wouldn’t

NLMax = Evaluate({@Max(@Tonumber(@DbColumn(“”;“”:“”;“($Num)”;1)))})

work ?

Btw I’m don’t know if @tonumber works with a list…

HTH

Subject: Thank you

Hello Yannick and thank you for your response.

I managed to get the code to work the way I wanted with:


Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim NL As Variant

Dim NLMax As Long

NL = Evaluate({@DbColumn(“”;“”:“”;“($Num)”;1)})

NLMax = Clng(NL(0))+1

Call source.fieldSetText (“OfficePhoneNumber”,Cstr(NLMax))

End Sub


This because the first column in the view ($Num) is sorted descending so the first value is always the largest (right?).

Now all I have to add is the @newdoc thing but that shouldn’t be too hard. =)

Thanks once again

Regards

Frank