Solved

dblookup, take highest number in view +1

Posted on 2008-06-20
12
457 Views
Last Modified: 2013-12-18
I have a hidden view called $nn12
I have a field called NextNumber.

On my form I have an action hotspot/button to that I want to set the value of NextNumber to the highest value in coloum 1 of the $nn12 view, but increase the value by an increment of 1.
Also please note this value a numberical value but it has been stored in a text field.

Formula language is easier for me to understand but willing to accept LS so long as it is commented so I can see whats what.

0
Comment
Question by:scribla
  • 6
  • 6
12 Comments
 
LVL 22

Accepted Solution

by:
mbonaci earned 500 total points
ID: 21830244
Sort the hidden view's column ascending.

Use function to get max value from view's column.

In your button (I presume the button is visible only in edit mode):

      Call uidoc.FieldSetText( CStr( getMaxNum( ) + 1 ) )
Function getMaxNum( ) As Long

	On Error Goto ErrHandler

	Dim s As New NotesSession

	Dim w As New NotesUIWorkspace

	Dim db As NotesDatabase

	Dim v As NotesView

	Dim lastDoc As NotesDocument

	

	Const fieldName$ = "NameOfNumberField"

	Const viewName$ = "NameOfView"

	

	Set db = s.CurrentDatabase

	Set v = db.GetView( viewName )

	Set lastDoc = v.GetLastDocument	

	If lastDoc Is Nothing Then Exit Function

	

	getMaxNum = Clng( lastDoc.GetItemValue( fieldName )(0) )

	

out:

	Exit Function

ErrHandler:

	Msgbox "Error in action - getMaxNum" & Chr$(10) & "Line: " & Cstr( Erl ) & Chr$(10) & "Err No: " & Err & ": " & Error$

	Resume out	

End Function

Open in new window

0
 
LVL 2

Author Comment

by:scribla
ID: 21830295
Thanks, could you tell me where I put the LS example, does this go on the form somewhere or into a script library? Excuse me I'm a total newb with LS
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 21830352
OK, to clarify,
your column has to be the first sorted column in the view!

By sorting the view entries ascending, we will get the highest value at the bottom (and vice versa, descending - top).
That means that we can get last doc and get its field's value (the first sorted column's formula).

Now, when we have the max value it's easy, increment it and write to field.

If you're new to LotusScript, to add function to your hotspot:
 - copy the function to clipboard (ctrl+c)
 - locate the hotspot's Declarations section
 - position the cursor in it and press paste (ctrl+v)
The function will be created bellow Terminate event.

Now you can call it (only) from hotspot's events (in our case - Click).
0
 
LVL 2

Author Comment

by:scribla
ID: 21830467
I am pasting "Call uidoc.FieldSetText( CStr( getMaxNum( ) + 1 ) )" into the buttons Click section.
The code in  the code snippet I am pasting into Declarations section.

When I try to save the form is say there is an LS error: Not a sub or function name: UIDOC

The click section when shows Call uidoc.FieldSetText( Cstr( getMaxNum( ) + 1 ) ) in red.
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 21830694
The code for button:

Dim w as New NotesUIWorkspace
Dim uidoc as NotesUIDocument

Set uidoc = w.CurrentDocument

Call uidoc.FieldSetText( Cstr( getMaxNum( ) + 1 ) )


Remember to change the fieldName and viewName constants in the function.
0
 
LVL 2

Author Comment

by:scribla
ID: 21830731
After changing the code in the Click section to the above, it now says 'Missing argument for FIELDSETTEXT'

I have changed fieldname & viewname to the field and view as nessisary in the function.

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Expert Comment

by:mbonaci
ID: 21830760
Sorry,
of course, the editor asks "What field do you want me to change?" :)

Call uidoc.FieldSetText( "NextNumber", Cstr( getMaxNum( ) + 1 ) )
0
 
LVL 2

Author Comment

by:scribla
ID: 21831070
Thanks works great, thank you.

I was just wondering... Is there any way I could change "Const viewName$ = "NameOfView" to get the "NameOfView" from a frield on the current document?

0
 
LVL 22

Expert Comment

by:mbonaci
ID: 21831865
Of course you can:
'The new code for the button:
 

Dim w as New NotesUIWorkspace

Dim doc As NotesDocument

Dim uidoc as NotesUIDocument

Dim viewName as String
 

Set uidoc = w.CurrentDocument

Set doc = uidoc.document  'here you get backend document (uidoc is front end - user interface)
 

viewName = doc.FieldThatHoldsTheValue(0)  'we use (0) because every field is actually an array
 

Call uidoc.FieldSetText( Cstr( getMaxNum( viewName ) + 1 ) )
 
 
 
 

'Change the function code like this (only function signature (first line) and Const line is changed):

Function getMaxNum( viewName As String ) As Long

        On Error Goto ErrHandler

        Dim s As New NotesSession

        Dim w As New NotesUIWorkspace

        Dim db As NotesDatabase

        Dim v As NotesView

        Dim lastDoc As NotesDocument

        

        Const fieldName$ = "NameOfNumberField"

                

        Set db = s.CurrentDatabase

        Set v = db.GetView( viewName )

        Set lastDoc = v.GetLastDocument 

        If lastDoc Is Nothing Then Exit Function

        

        getMaxNum = Clng( lastDoc.GetItemValue( fieldName )(0) )

        

out:

        Exit Function

ErrHandler:

        Msgbox "Error in action - getMaxNum" & Chr$(10) & "Line: " & Cstr( Erl ) & Chr$(10) & "Err No: " & Err & ": " & Error$

        Resume out      

End Function

Open in new window

0
 
LVL 22

Expert Comment

by:mbonaci
ID: 21831904
Be careful in multiuser environment.

If two users open the new doc at the same time (before other user saves his doc) what would happen?


I'm glad I was able to help you.
Mb¤
0
 
LVL 2

Author Comment

by:scribla
ID: 21832042
Many thanks.

I am validating the generated number against the same view using DBLookup when the doc is saved.
Just means the user will have to generate another number using our new button if this happens, which should be very rare.
0
 
LVL 2

Author Comment

by:scribla
ID: 21832500
mbonaci, I have asked a related question if you would like to take a look for me. Thanks.

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/Lotus_SmartSuite/Lotus_Notes/Q_23502727.html
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now