?
Solved

Trouble with SaveOptions

Posted on 2006-04-04
32
Medium Priority
?
435 Views
Last Modified: 2013-12-18
Having some trouble with my saving on a doc I have the code below in the SaveOptions field. I also have a validation on the exiting of the username field to make sure the user has not already started a version of this doc before. Now when it runs the script and validates that this would be a duplicate, it closes the form but it saves a copy anyways. How can I tweak these 2 to validate properly but not save the duplicate.

Code in Saveoptions field:
@If(@IsNewDoc ; "1" ; "0")

Exiting code in username field:
Sub Exiting(Source As Field)
      Dim workspace As New NotesUIWorkspace
      Dim session As New NotesSession
      Dim username As String
      Dim ndoc As NotesDocument
      Dim cdoc As NotesDocument
      Set uidoc = workspace.CurrentDocument
      Set db = session.CurrentDatabase
      Set ndoc = uidoc.Document
      Set view = db.GetView("(completed)")
      Call uidoc.Save
      username = uidoc.FieldGetText( "username")
      key = username
      Set cdoc = view.GetDocumentbyKey(key)
      If cdoc Is Nothing Or cdoc.NoteID= ndoc.NoteID Then
            Exit Sub
      Else
            Msgbox "You have already started a Self-Assessment, please edit that version."
            Set doc = uidoc.Document
            doc.SaveOptions = "0"
            Call uidoc.close
      End If
End Sub
0
Comment
Question by:jforget1
  • 13
  • 10
  • 5
  • +1
31 Comments
 
LVL 14

Expert Comment

by:p_partha
ID: 16374092
Don't put the code in the exiting event, Try putting the code in query save there you have option of not saving the document by using continue = false and that's the best way to code as the user may avoid the firing of exiting event by not tabbing the field
0
 

Author Comment

by:jforget1
ID: 16374144
The only problem with that is I also don't want the user to go through the whole form and then find out it is a duplicate. The entry of the form is long and would be bad to find out after all the data entry.
0
 
LVL 14

Expert Comment

by:p_partha
ID: 16374177
Don;t have any formula on teh saveoptions, but just have the field, and why do u do the uidoc.save , remove that line it should work..

Partha
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 14

Expert Comment

by:p_partha
ID: 16374185
SO ideally your code should be :

Dim workspace As New NotesUIWorkspace
     Dim session As New NotesSession
     Dim username As String
     Dim ndoc As NotesDocument
     Dim cdoc As NotesDocument
     Set uidoc = workspace.CurrentDocument
     Set db = session.CurrentDatabase
     Set ndoc = uidoc.Document
     Set view = db.GetView("(completed)")
     username = uidoc.FieldGetText( "username")
     key = username
     Set cdoc = view.GetDocumentbyKey(key)
     If cdoc Is Nothing Or cdoc.NoteID= ndoc.NoteID Then
          Exit Sub
     Else
          Msgbox "You have already started a Self-Assessment, please edit that version."
          Set doc = uidoc.Document
          doc.SaveOptions = "0"
          Call uidoc.close
     End If
0
 

Author Comment

by:jforget1
ID: 16374189
Do I make the SaveOptions Editable or Conputed?
0
 

Author Comment

by:jforget1
ID: 16374226
I get an Object variable not set when I rem the Uidoc.Save line.
0
 
LVL 14

Expert Comment

by:p_partha
ID: 16374245
what line you get the error, use debugger and tell us the exact line that is causing the error
0
 

Author Comment

by:jforget1
ID: 16374293
It is happening at this line

Set cdoc = view.GetDocumentbyKey(key)
0
 
LVL 14

Expert Comment

by:p_partha
ID: 16374311
that means that view doesn't exist. check whether the view by that name exists, or is it spelled correctly

partha
0
 

Author Comment

by:jforget1
ID: 16374348
If i take off the rem on the uidoc.save line I do not get the error.
0
 
LVL 14

Expert Comment

by:p_partha
ID: 16374382
If you put uidoc.save  what happens is, even before u check whether teh document needs to be saved or not, it's already saved. So when you say uidoc.close , the document had been saved 20 lines before and it simply closes the document, I feel the error is somewhere else, what do u mean by take off the rem on uidoc.save , just remove that line

Partha
0
 

Author Comment

by:jforget1
ID: 16374421
I took that line out completely and I get the Object variable not set error again. I will keep trying.
0
 
LVL 14

Expert Comment

by:p_partha
ID: 16374464
Try this:

Dim workspace As New NotesUIWorkspace
     Dim session As New NotesSession
     Dim username As String
     Dim ndoc As NotesDocument
     Dim cdoc As NotesDocument
     Set uidoc = workspace.CurrentDocument
     Set db = session.CurrentDatabase
     Set ndoc = uidoc.Document
     Set view = db.GetView("(completed)")
if view is nothing then
msgbox " the view is not found please check whether u have spelled me correct, try removing the bracket and check
end if
     username = uidoc.FieldGetText( "username")
key = username
     Set cdoc = view.GetDocumentbyKey(key)
     If cdoc Is Nothing Or cdoc.NoteID= ndoc.NoteID Then
          Exit Sub
     Else
          Msgbox "You have already started a Self-Assessment, please edit that version."
          Set doc = uidoc.Document
          doc.SaveOptions = "0"
          Call uidoc.close
     End If
0
 

Author Comment

by:jforget1
ID: 16374520
I pasted yours in directly and get the same Object error at the same Set cdoc line as before.
0
 
LVL 14

Expert Comment

by:p_partha
ID: 16374552
Did you get any message like view not found.
0
 

Author Comment

by:jforget1
ID: 16374560
No it went right past that. I know the view is there.
0
 
LVL 14

Assisted Solution

by:p_partha
p_partha earned 400 total points
ID: 16374614
Hey
Try removing this condition : Or cdoc.NoteID= ndoc.NoteID , why did you add it , it's never going to be the same for two documents

Partha
0
 

Author Comment

by:jforget1
ID: 16374651
I did not write the initial but I believe that is what is doing the comparison if there is a conflict.
0
 
LVL 14

Expert Comment

by:p_partha
ID: 16374681
I assume that you want to check the whole condition only if it is a new document right, for that you can just use
 If uidoc.IsNewDoc Then . I am not sure what's the use of noteid comparison

partha
0
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 800 total points
ID: 16376140
Just barging in... ;)

Can you describe the current situation?

My questions already (backing Partha with what he suggested at the top):
- this code should never be in an Exiting of a field (don't yell, suggestion follows ;)
- why use NotesUIDocument when you can use a NotesDocument?
- why call GetDocumentByKey with only 1 parameter?
- why is key not declared
- why is there a Save before you need it (answered later on)

My suggestion (as promised):
- put the code in a Function called UserExists
- call the same function from the field's Exiting and the form's QuerySave events
- instead of the premature Save, get your logic right!

    find document for username
    if document doesn't exist then
        ok
    elseif new document then ' now we know current document is not valid!
        not ok
    elseif this.noteid=found.noteid then ' same document
        ok
    else
        not ok
    fi
    if not ok then
        Fire!!
    end if
0
 
LVL 22

Accepted Solution

by:
mbonaci earned 800 total points
ID: 16379295
Hi jforget1,
you're getting the error because of this line:

>  If cdoc Is Nothing Or cdoc.NoteID= ndoc.NoteID Then

I presume you thought when there's Or in If statement and the first part (if cdoc Is Nothing) evaluates to False that then the rest of the statement wont be executed.
Wrong, LotusScript isn't "smart" as C, so you must split that in two lines, like this:

    If cdoc Is Nothing Then Exit Sub
    If cdoc.NoteID= ndoc.NoteID Then Exit Sub


PS I'm behind Sjef's advices here 100%.

Hope this helps,
Marko
0
 

Author Comment

by:jforget1
ID: 16380619
I did not write the code, got this from someone else, I just want to do an evaluation if the person has already started a form for themselves without them filling out the entire thing and then it tells them it is a duplicate. I am open to any new code or suggestions, I will try and work in the changes from Sjef.
0
 

Author Comment

by:jforget1
ID: 16380687
mbonaci

Adding the two lines of code you suggested worked, it did all the evaluations properly. Thanks to all for the help.

Joe
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16380727
Just give an A next time...
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 16391186
jforget1,
Seriously, why B?
My answer was right on the spot.

http://www.experts-exchange.com/help.jsp#hi73

Marko
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16391252
"My" ???   "Our" !!
0
 

Author Comment

by:jforget1
ID: 16391282
I am sorry I did not realize that was a real big deal, can I change it, I will. It was my bad, I really do appreciate the help.
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 16391307
sorry Sjef, "Our" of course, I sometimes tend to be a bit egoistic ;)

As I already said, all great tips, you know I didn't mean that ;)

Marko
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16399473
jforget1, just put a question in Community Support asking to reopen this question. Don't forget the link to this one!
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16399475
You can also ask them to just change the grade...
0
 

Author Comment

by:jforget1
ID: 16399693
I have requested this be changed.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

850 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