Jean
Jean

Reputation: 42

Message displaying - asking if want to save document - shouldn't display written in Lotusscript for lotus Notes

I have a form that has an approve and deny button. These buttons will only display when the document is in edit mode.

The document will have the status of "Awaiting Manager Approval" and the user presses the Approve button and they are asked if they want to save the change. If they answer "Yes", the change is saved, if they answer "No", the document is to close and if they answer "Cancel", the user is brought back to the document just as it was when they pressed the approve button.

Here is my issue, when the document is "Awaiting Manager Approval", and the user presses "No", the document automatically closes as it should. When the document moves to the next step of the workflow - "Awaiting Sales Approval", the user presses the Approve button and then presses No the same as in the previous step, but instead of automatically closing as it should the user is presented with the second message asking if they want to save the document.

I have looked at the code and both use the following script in the "Approve" button and there is nothing in the Query close event both on the subform or form.

Can anyone tell me why the message is displaying at the second step of the workflow? I don't want the message to display since the user answered "No".

Below is the code for the Approve button.

Code for button in LotusScript :

Sub Click(Source As Button) 
        Dim workspace As New NotesUIWorkspace 
        Dim askme As Integer 
        Dim tellme As Integer 
        Dim holdValue As String 
        Dim holdValue2 As String 
        Dim uidoc As NotesUIDocument 
        Dim doc As NotesDocument 
        Dim boxType As Long, answer As Integer 
        boxType& = MB_YESNOCANCEL + MB_ICONQUESTION 
        Set uidoc = workspace.CurrentDocument 

        Set doc = uidoc.Document         
        Dim num As Integer 


        If (uidoc.EditMode = True) And (DocWasSaved = False) Then 
                holdvalue = uidoc.EditMode                         
                askMe = Messagebox("Do you wish to continue?",  boxType&, "Continue?") 
                Select Case askme 

                Case 2 
                       'Equals Cancel response - no action - goes back into document.         
                Case 6         
                       'Equals Yes response - saves document                 
                       Call uidoc.FieldSetText("Action", "Approve")                 
                       Call uidoc.FieldSetText("PostAction", "Approve") 
                       Call uidoc.FieldSetText("SaveOptions", "1") 
                       Call uidoc.FieldSetText("CloseFlag", "Yes")                                 
                       Call uidoc.Save                                 
                       Call uidoc.close                         
                Case 7 
                       'User answered No, doesn't save and closes document. 
                        Call uidoc.Close                         
                End Select 
        Else                         
        End If         

End Sub

Upvotes: 0

Views: 5753

Answers (2)

Karl-Henry Martinsson
Karl-Henry Martinsson

Reputation: 2795

Instead of messing with the SaveOpetions field, you could also make the changes in the backend, after you close the document. Just remember, that if any field on the form has been modified/changed, you will get that prompt. That is why I would suggest a uidoc.Save() even when canceling.

Here is my (untested) code:

Sub Click(Source As Button)
 Dim ws As New NotesUIWorkspace
 Dim uidoc As NotesUIDocument
 Dim doc As NotesDocument
 Dim result As Integer
 Dim boxType As Long

 boxType = MB_YESNOCANCEL + MB_ICONQUESTION
 Set uidoc = workspace.CurrentDocument

 result = Messagebox("Do you wish to continue?", boxType, "Continue?")
 Select Case result
 Case 2
   'Equals Cancel response - no action - goes back into document. 
 Case 6 
   'Equals Yes response - saves document and closes it
   Call uidoc.Save()
   set doc = uidoc.Document
   Call uidoc.Close(True)
   Call doc.ReplaceItemvalue("Action", "Approve") 
   Call doc.ReplaceItemvalue("PostAction", "Approve")
   Call doc.ReplaceItemvalue("SaveOptions", "1")
   Call doc.ReplaceItemvalue("CloseFlag", "Yes") 
   Call doc.Save(True,False)
 Case 7
   'User answered No, doesn't save and closes document.
   'Note: If any field has changed, the user will get the save yes/no prompt.
   'I would add:
   'Call uidoc.Save()
   Call uidoc.Close 
End Select

End Sub 

Upvotes: 0

Naveen
Naveen

Reputation: 6936

You could try using the SaveOptions field to suppress the additional dialog of "Do you want to save this document?". Setting the field value to "0" will make it possible to close the document without that prompt. Refer this article for more information.

So your code sample would be similar to this:

Call uidoc.Save
Call uidoc.FieldSetText("SaveOptions", "0")
Call uidoc.Close

Upvotes: 2

Related Questions