NotesUIDocument Save Changes Even Though Saved...

I've listed my code below.  I'm wondering why, after this script runs, Notes still prompts the user to Save Changes.  It's driving me insane.

As you can see, I call uidoc.Save right before uidoc.Close, so I'm wondering if this is one of the millions of problems in Notes.  Is there any way around it?

Thanks for your time and help.

-Cory






Function SubmitForITGovApproval ( szForm As String ) As Integer
      On Error Goto HandleError
      
      Dim szFieldName As String
      Dim szLabel As String
      Dim szQuestion As String
      Dim szTitle As String
      
      Dim uidoc As NotesUIDocument
      Dim uiw As New NotesUIWorkspace
      
      SubmitForITGovApproval = True
      
      szQuestion = "Are you sure you want to submit this document for IT Gov. approval?"
      szTitle = "Submit For Approval?"
      
      If Messagebox( szQuestion, MB_YESNO, szTitle ) = MB_YES Then
            Set uidoc = uiw.CurrentDocument
            uidoc.EditMode = True
            uidoc.Save
            
            If szForm = CONTRACT_FORM Then
                  uidoc.Document.ContractStatus = STATUS_3
            Else
                  uidoc.Document.SOWStatus = STATUS_3
            End If
            
            uidoc.Save
            uidoc.Close
      End If
      
Finish:
      Exit Function
HandleError:
      SubmitForITGovApproval = False
      Messagebox "Error submitting for IT Gov. approval: (" & Erl() & " - " & Error() & ")"
      Resume Finish
End Function
LVL 13
cLFlaVAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sjef BosmanGroupware ConsultantCommented:
If you call uidoc.Save yourself, then you trigger the QuerySave and PostSave methods. You should do this differently, in order to get the proper sequence.

Is it necessary that the document is in edit-mode?? If not, then don't use the uidoc, but use uiw.currentdocument.document all the time!

Function SubmitForITGovApproval ( szForm As String ) As Integer
     On Error Goto HandleError
     
     Dim szFieldName As String
     Dim szLabel As String
     Dim szQuestion As String
     Dim szTitle As String
     
     Dim uidoc As NotesUIDocument
     Dim doc As NotesDocument
     Dim uiw As New NotesUIWorkspace
     
     SubmitForITGovApproval = True
     
     szQuestion = "Are you sure you want to submit this document for IT Gov. approval?"
     szTitle = "Submit For Approval?"
     
     If Messagebox( szQuestion, MB_YESNO, szTitle ) = MB_YES Then
          Set uidoc = uiw.CurrentDocument
          Set doc= uidoc.Document
'          uidoc.EditMode = True
'          uidoc.Save
         
          If szForm = CONTRACT_FORM Then
               doc.ContractStatus = STATUS_3
          Else
               doc.SOWStatus = STATUS_3
          End If
         
          doc.Save True, False
          uidoc.Close ' if need be
     End If
     
Finish:
     Exit Function
HandleError:
     SubmitForITGovApproval = False
     Messagebox "Error submitting for IT Gov. approval: (" & Erl() & " - " & Error() & ")"
     Resume Finish
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cLFlaVAAuthor Commented:
Thanks a ton for your suggestions.  One thing though, is that I've got an Audit Trail running on the form's querysave event, so that's why I was calling it from there.

This script is part of a script library, the audit trail is part of a separate script library.  The audit trail initiates in the form's post open event, and gets compared on the querysave event.

So, do you have any suggestions as to how to handle this?  Thanks.
0
cLFlaVAAuthor Commented:
Also, if this document happens to initially be in edit mode, then won't this:

doc.Save True, False
uidoc.Close

result in the same prompt?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

cLFlaVAAuthor Commented:

Ok, I've got it working (better) now.  However, if the document is in edit mode, it will still prompt the user after the script runs:



Function SubmitForITGovApproval ( szForm As String ) As Integer
      On Error Goto HandleError
      
      Dim s As New NotesSession
      
      Dim szFieldName As String
      Dim szLabel As String
      Dim szQuestion As String
      Dim szTitle As String
      
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Dim uiw As New NotesUIWorkspace
      
      SubmitForITGovApproval = True
      
      szQuestion = "Are you sure you want to submit this document for IT Gov. approval?"
      szTitle = "Submit For Approval?"
      
      If Messagebox( szQuestion, MB_YESNO, szTitle ) = MB_YES Then
            Set uidoc = uiw.CurrentDocument
            Set doc = uidoc.Document
            
            If szForm = CONTRACT_FORM Then
                  doc.ContractStatus = STATUS_3
            Else
                  doc.SOWStatus = STATUS_3
            End If
            
            WriteLine "submitted this document for IT Gov. Approval.", doc
            doc.Save True, False
            uidoc.Close
      End If
      
Finish:
      Exit Function
HandleError:
      SubmitForITGovApproval = False
      Messagebox "Error submitting for IT Gov. approval: (" & Erl() & " - " & Error() & ")"
      Resume Finish
End Function




I know it's because of uidoc.Close, is there any way to bypass this?
0
Sjef BosmanGroupware ConsultantCommented:
So your function SubmitForITGovApproval is actually called from the QuerySave event? Then DON'T call Save() from inside the function, but left the QuerySave finish it's job, and just add the following line to the QuerySave:
    continue= SubmitForITGovApproval
0
cLFlaVAAuthor Commented:
ahh, but there are 5 other very very similar functions that will be called.  These are called from action buttons.  The querysave event calls some other function - unrelated.
0
p_parthaCommented:
You can use saveoptions field, something like this:

call uidoc.fieldsettext("SaveOptions", "0")
call uidoc.close

partha
0
Sjef BosmanGroupware ConsultantCommented:
Hmmm. Back to square one. Okay, what do you want? You didn't tell me the whole story, did you? I sure need to know more:
- from where do you want to call this particular function?
- can the document be in both edit-mode or read-mode when the function is called? or only edit-mode?
- why don't you pass the doc as argument for the function, and let the caller handle the saving??
0
Sjef BosmanGroupware ConsultantCommented:
Hey Bro, Don't you have to be in a meeting??
0
p_parthaCommented:
It's holiday mood here, so no meeting only stealing :)

Partha
0
cLFlaVAAuthor Commented:
Would I have to set this SaveOptions field every time I'm saving something, then?  Or will it reset all the time?
0
cLFlaVAAuthor Commented:
sjef-

 - these functions will be called from a form when the user clicks on an action button at the top of the screen.
 - the document can be in both edit and read mode.
 - I don't know, that's just not the way I set it up.
0
Sjef BosmanGroupware ConsultantCommented:
Grrrrrrr!

Sjef :D
0
p_parthaCommented:
hey
This is your initial code:

   On Error Goto HandleError
   
     Dim szFieldName As String
    Dim szLabel As String
    Dim szQuestion As String
    Dim szTitle As String
   
     Dim uidoc As NotesUIDocument
    Dim uiw As New NotesUIWorkspace
   
     SubmitForITGovApproval = True
   
     szQuestion = "Are you sure you want to submit this document for IT Gov. approval?"
    szTitle = "Submit For Approval?"
   
     If Messagebox( szQuestion, MB_YESNO, szTitle ) = MB_YES Then
         Set uidoc = uiw.CurrentDocument
         uidoc.EditMode = True
         uidoc.Save
         
         If szForm = CONTRACT_FORM Then
              uidoc.Document.ContractStatus = STATUS_3
         Else
              uidoc.Document.SOWStatus = STATUS_3
         End If
         
         uidoc.Save
call uidoc.fieldsettext("saveoptions","0")
         uidoc.Close
    End If

This will prevent the save prompt but as sjef pointed out ,every save will result in querysave event being called

Partha
0
Sjef BosmanGroupware ConsultantCommented:
I call this a kludge...
0
p_parthaCommented:
Have to go to a meeting now  did i answer anythign here ?:-)

Partha
0
cLFlaVAAuthor Commented:
With my ammended code (with the help of sjef above) and your suggestion of the SaveOptions field, though, I should get the desired result?

Basically, since the document is being saved from the backend during the whole process, and the user will not be able to change any fields during the function's processing, there's no need to re-ask "should it save".  Does this make sense?

So, I will now try putting your saveoptions solution into my newer code.  Do I have to create an actual field called saveoptions?  Should it be computed?  computed when composed?
0
cLFlaVAAuthor Commented:
and I call it: "i don't yet know any better"
0
p_parthaCommented:
Yeah it's better you have a field by name saveoptions in the form, and just editable would do

partha
0
cLFlaVAAuthor Commented:
ok thanks, i'll try it now.
0
p_parthaCommented:
But make sure you manipulate it accordingly (i.e when you edit the documnet later, probably before saving set the saveoptions to "1" and save it...


partha
0
cLFlaVAAuthor Commented:
well, if we're setting 0 just before close, then closing it, it shouldn't ever "remember" the 0 i'm setting it to...
0
Sjef BosmanGroupware ConsultantCommented:
LOL

Although he's my bro, I consider the SaveOptions-solution in this case a 'last resort' solution. If all else fails, then use it, reluctantly. It's the high way where you could easily take my way, if you would be so kind to forgive the expression. Could you please answer the questions I had before? I sincerely question the logic of your form's buttons and actions. Could you please shed some light??

Sjef
0
cLFlaVAAuthor Commented:
ok, which question - the third?  I didn't really understand it.

  >>  - why don't you pass the doc as argument for the function, and let the caller handle the saving??

Could you explain a little more?  Thanks.
0
p_parthaCommented:
Bro,
This is one of the "Frequently" used workarounds. But you are right, there are elegant ways of writing this whole stuff.. He could have written everythign in querysave and in the code which calls this functoin he cud have just given :

@command([filesave])
@command([fileclosewindow])

Partha
0
Sjef BosmanGroupware ConsultantCommented:
Okay. On second thought, add another parameter that will take care of saving the document if required

I assume you have in your QuerySave function something like
    .
    ok= SubmitForITGovApproval
    .

Now instead of saving INSIDE the function SubmitForITGovApproval, you skip the saving and you let QuerySave finish its job. Like this:

In QuerySave:
    Dim uidoc As NotesUIDocument
    Dim ws As NotesUIWorkspace

    Set uidoc= ws.CurrentDocument
    ok= SubmitForITGovApproval(uidoc.Document, False)
    If Not ok Then continue= False ' will stop saving the document

And in your function SubmitForITGovApproval:
    Function SubmitForITGovApproval(doc As NotesDocument, dosave As Integer)
    .
    SubmitForITGovApproval= False ' this line isn't required
    If MessageBox ... Then
        SubmitForITGovApproval= True
        If dosave Then
            Call doc.Save(True, False)
        End If
    End If

That's all. If you call the same function from somewhere else, you can force saving using
    Call SubmitForITGovApproval(doc, True)

Am I making myself a little clear??
0
cLFlaVAAuthor Commented:
But there are also times when a user can save the form without submitting it for approval.  Plus, there are five separate approval stages.
0
p_parthaCommented:
cLFlava,

Everything is a "If condition" in querysave

Partha
0
cLFlaVAAuthor Commented:
My QuerySave:


Sub Querysave(Source As Notesuidocument, Continue As Variant)
      On Error Goto HandleError
      ' assign a unique id if this is a new document
      If Source.IsNewDoc And Source.Document.ContractNumber( 0 ) = "" Then
            AssignUniqueID Source, CONTRACT_FORM
      Else
            ' log any changed fields
            CompareValues CONTRACT_FORM
      End If
Finish:
      Exit Sub
HandleError:
      Continue = False
      Resume Finish
End Sub
0
cLFlaVAAuthor Commented:
i've got two meetings now - i'll definitely be back to continue this.

thanks so much for your help so far.
0
qwaleteeCommented:
Handle it the way Lotus handles it in mail.  The actions buttons -- save as draft, send and file, simple send -- all have the same very basic code:

1) Set an indicator field to a value unique to the particular action button
2) save and close window

This effectively just causes the QuerySave/PostSave/QueryClose to do allthe processing, and those functions call a routine in a script library, and THOSE routines have access to some common code.

At a simplified level, you might have:

Action SUBMIT:
FIELD ProcessingOption := "SUBMIT";
@Command([FileSave]);
@Command([FileClose);

Action SAVE DRAFT:
FIELD ProcessingOption := "DRAFT";
@Command([FileSave]);
@Command([FileClose);


QuerySave:
Select Case Source.Document.ProcessingOption(0)
    Case "DRAFT"
        Call UpdateAuditHistoryRoutine
        Source.Document.ProcessingOption = "OKTOSAVE"
    Case "SUBMIT"
        If CheckValidationsRoutine() Then
            Call UpdateAuditHistoryRoutine
            Source.Document.ProcessingOption = "OKTOSAVE"
        Else
            Continue = False 'prevent save
            Source.Document.ProcessingOption = ""
        End If
    Case Else
        Msgbox "Unknown save process",,Source.Document.ProcessingOption(0)
        Continue = False
End Select


PostSave:
If Source.Document.ProcessingOption(0) = "OKTOSAVE" Then
    Source.Document.ProcessingOption = "SAVED"
Else
    Source.Document.ProcessingOption = ""
End If

QueryClose:
If Source.Document.ProcessingOption(0) <> "SAVED" Then
    Source.Document.ProcessingOption = ""
    Msgbox "Unknown close process",,Source.Document.ProcessingOption(0)
End If

0
Bozzie4IT ArchitectCommented:
Or don't use notesuidocument to save/set anything.  There's no need, because you are closing it anyway :

Function SubmitForITGovApproval ( szForm As String ) As Integer
     On Error Goto HandleError
     
     Dim szFieldName As String
     Dim szLabel As String
     Dim szQuestion As String
     Dim szTitle As String
     
     Dim uidoc As NotesUIDocument
     Dim uiw As New NotesUIWorkspace
     
     SubmitForITGovApproval = True
     
     szQuestion = "Are you sure you want to submit this document for IT Gov. approval?"
     szTitle = "Submit For Approval?"
     
     If Messagebox( szQuestion, MB_YESNO, szTitle ) = MB_YES Then
          Set uidoc = uiw.CurrentDocument
if uidoc.editmode then
' save state
Call uidoc.save()
end if
                   
          If szForm = CONTRACT_FORM Then
               uidoc.Document.ContractStatus = STATUS_3
          Else
               uidoc.Document.SOWStatus = STATUS_3
          End If
         
          uidoc.document.save( true, false )
uidoc.document.saveoptions = "0" ' this line may or may not be necessary
          uidoc.Close
     End If
     
Finish:
     Exit Function
HandleError:
     SubmitForITGovApproval = False
     Messagebox "Error submitting for IT Gov. approval: (" & Erl() & " - " & Error() & ")"
     Resume Finish
End Function
0
Sjef BosmanGroupware ConsultantCommented:
Hi Tom, please re-read from the start... ;)

I think a code review is more appropriate. Sorry clFlaVa, not to criticize you, but there seme to be some serious misconceptions in the code, about how and where documents can be saved, about UIDocuments and Documents, etc.
0
cLFlaVAAuthor Commented:

Yes, sjef, I understand there are misconceptions.  This is the only way for me to learn.  Thanks, I'll let you all know what my solution ends up being.
0
Sjef BosmanGroupware ConsultantCommented:
You'll get by with a little help... Do be back! You're learning the right way.
0
cLFlaVAAuthor Commented:
Alright, here's an update.
I took many of your pieces of advice.  My main concern was the advice from sjef:

  >> Sorry clFlaVa, not to criticize you, but there seme to be some serious misconceptions in the code, about how and where documents can be saved, about UIDocuments and Documents, etc.

I've changed the functionality to the below, and it seems to work perfectly.  Please let me know if you see any weak points.

--- --- --- --- ---

QUERYSAVE:
Sub Querysave(Source As Notesuidocument, Continue As Variant)
      On Error Goto HandleError
      
      If Source.IsNewDoc And Source.Document.ContractNumber( 0 ) = "" Then
            ' give the contract a unique identifier
                ' Note: There are no calls to doc.Save NOR uidoc.Save in here
            AssignUniqueID Source, CONTRACT_FORM
      Else
            ' determine if any changes were made and record the changes
                ' Note: There are no calls to doc.Save NOR uidoc.Save in here
            CompareValues CONTRACT_FORM
      End If
      
Finish:
      Exit Sub
HandleError:
      Continue = False
      Messagebox "An error occurred.  Contract was not saved.", , "Error Saving..."
      Resume Finish
End Sub

--- --- --- --- ---

Each Action Button Looks Very Similar To This (the action buttons can only be seen in edit mode) :
Sub Click(Source As Button)
      If Messagebox( "Are you sure you want to submit this contract for PM approval?", MB_YESNO, "Submit?") = MB_YES Then
                ' No call to doc.Save NOR uidoc.Save in ValidateContract function
            If ValidateContract Then
                  Dim uiw As New NotesUIWorkspace
                  Dim uidoc As NotesUIDocument
                  Dim doc As NotesDocument
                  
                  Set uidoc = uiw.CurrentDocument
                  Set doc = uidoc.Document
                  doc.ContractStatus = STATUS_2
                  
                        ' No call to doc.Save NOR uidoc.Save in this function
                  WriteLine "submitted this contract for PM approval."
                  
                  uidoc.Save
                  uidoc.Close
            End If
      End If
End Sub
0
Sjef BosmanGroupware ConsultantCommented:
Better :) Only one question:
               ' No call to doc.Save NOR uidoc.Save in this function
               WriteLine "submitted this contract for PM approval."
               
-->          uidoc.Save ' in contradiction with the comment above!!
               uidoc.Close

And? Does this work for you? If it does, we're all happy.
0
cLFlaVAAuthor Commented:
I meant, no call to those save functions within the function WriteLine...

I thought the main problem I was having was that I was calling save in multiple places, whereas in my new code, i'm only calling it once, at the very end.

It works, just wanted to make sure it made better sense from the saving in uidoc/doc perspective...
0
Sjef BosmanGroupware ConsultantCommented:
Looks great! Very transparent code.
0
cLFlaVAAuthor Commented:
Cool thanks.

I think I'm going to do 80-20 for this between sjef and p_.

Any recommendations otherwise?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.