Solved

Get number from view

Posted on 2004-04-06
7
258 Views
Last Modified: 2013-12-18
Can somebody please check what's wrong? I need to get the highest number in my Ticket no view. This view is sorted Desc, so the number on top of the view is always the highest one, after I get that number I need to grab it increment it and assign  this number to the new document. I have this code in Querysave.

Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim Num As String
Set db = session.CurrentDatabase
Set view = db.GetView("Ticket No.")
Set doc = view.GetFirstDocument
doc.seqnum = Num     ' seqnum is the name of the 1st column in Ticket No.
Msgbox Num
If  doc.fld_CDseqnum(0) <> 0 Then    
  ' Increment the sequence number
End If
0
Comment
Question by:cyle
  • 3
  • 2
  • 2
7 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 10768807
   Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim view As NotesView
    Dim doc As NotesDocument
    Dim Num As String
    Set db = session.CurrentDatabase
    Set view = db.GetView("Ticket No.")
    Set doc = view.GetFirstDocument
If doc Is Nothing Then
    Num="1"
Else
    Num= CStr(CInt(doc.seqnum(0)) + 1)
End If        
    doc.seqnum = Num     ' seqnum is the name of the 1st column in Ticket No.
    Msgbox Num
    If  doc.fld_CDseqnum(0) <> 0 Then    
      ' Increment the sequence number
    End If


At least check for doc Is Nothing.
0
 

Author Comment

by:cyle
ID: 10768837
Num= CStr(CInt(doc.seqnum(0)) + 1) ---- This gives me a type mismatch error.
0
 
LVL 14

Expert Comment

by:p_partha
ID: 10768861
msgbox doc.sequnum(0)

It might be a empty string ("")

Partha
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 14

Expert Comment

by:p_partha
ID: 10768864
sorry typo
msgbox doc.seqnum(0)

Partha
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 150 total points
ID: 10768915
I have some trouble with your original code: where is Num coming from, why is it a String, and why did you have doc.seqnum= Num?

Consider the following (but don't implement it by Cut&Paste!):

    If doc Is Nothing Then
        Num= 1
    Else
        Num= doc.ColumnValues(0) +1
    End If

It's even faster this way. Make seqnum a number, to be used in the first column of the view. If you start testing, do remove all older documents, for they might not have a seqnum-field...
0
 

Author Comment

by:cyle
ID: 10769058
Okey, I got the highest number using bosman's solution, "for 50 points!!!!" I need to FieldSetText this number to the form.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 10772627
I hate FieldSetText and FieldGetText! I think it's not very frequently used, for there is doc.GetItemValue("fieldname")(0) or doc.fieldname (that doesn't work in all cases, e.g. with field that have the name of a reserved LS-word). The advantage of doc.fieldname(0) over uidoc.FieldGetText("fieldname") is that the first will give you the interpreted value of the field, tha latter only the text and you have to do the interpretation yourself: trimming, text-to-number translation, and multiple value splitting. In most cases you will see the following (in lowercase):

dim ws as new notesuiworkspace
dim uidoc as notesuidocument
dim doc as notesdocument
dim v as variant ' assume multiple value field

set uidoc= ws.currentdocument
set doc= uidoc.document
forall v_i in v
    ' do something with v_i
end forall

And, you're welcome!
0

Featured Post

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

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…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

12 Experts available now in Live!

Get 1:1 Help Now