Solved

dblookup, take highest number in view +1

Posted on 2008-06-20
12
460 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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
 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Encrypted Mail message in a NSF 10 30
External emails not coming through 3 107
Lotus Notes Calendar Issue 5 111
Lotus Notes – Domino Document Manager 4 113
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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