Problem : Force user to close form with action button (Lotus Script)

Problem : Force user to close form with action button (Lotus Script)

I need to force the user to close the form using the Cancel action button I’ve created, I have this code on the action button:

@Prompt([YesNo]; “Cancel This SSR?”; “This SSR and all actions will be deleted”);
FIELD Status := “Cancelled”;
@Command([FileSave]);
@Command ([CloseWindow])

I got the following code from a previous post, my main problem is that I already have a post open event on the form in Lotus script. Is there anyway of doing this in script? Or is there another method in Lotus script I can use that will not allow the user to exit the form other then the Cancel button?

How do you force a user to use a button to close a form?

This code satisfies three requirements:
1) prevent users from closing a form via menu or keyboard controls; only the action button can be used for closing
2) only use ONE field to accomplish to keep application overhead down
3) depending on a value in a status field, action button should issue file close

AllowClose field: Editable, Text, Hidden

Default value = “0”
Validation = @If(AllowClose = “0”; @Failure(…); @Success)
Action Button:
FIELD AllowClose := “1”;
………..

Form PostOpen Event:
FIELD AllowClose := “0”;
@SetField(“AllowClose”; “0”)

That’s all


Solution: Force user to close form with action button (Lotus Script)

A couple of suggestions…

On the form postopen event, you would need to set the values of the cancelFlag and the AllowClose fields if the form is being edited.

On the form postquerychange, you would also need to set the values of the cancelflag and the allowclose fields if the form was first opened in read mode and then switched to edit mode.

If you don’t want the “Do you want to save your changes” to appear after opening the form (because when you set these values in the postopen or postquerychange, the form is CHANGED, and the dialog box will appear, then you also would need to create a SaveOptions field.  You would set the value to “1” to display the Dialog Box, and also to allow the form to save.  You would set it to “0” if you don’t want the dialog box to appear and not want the form to save.

So,
First create a SaveOptions Field, editable, hidden, text, defaultValue=”1″
Create your AllowClose field, editable, hidden, text, defaultValue=”0″
If you want to trap the canceled event button, then create the CancelFlag field, editable, hidden, text, defaultValue=””

In the postOpen event paste the following code(Make sure I’ve spelled canceled the same way you have):

Sub Postopen(Source As Notesuidocument)
If source.editmode Then
Call source.FieldSetText(“AllowClose”,”0″)
Call source.fieldSetText(“SaveOptions”,”1″)
If Not source.IsNewDoc Then
If  Ucase(source.FieldGetText(“Status”))<>”CANCELED” Then
Call source.fieldSetText(“CancelFlag”,””)
End If
End If
End If
End Sub

Paste the SAME code for the PostModeChange event:
Sub Postmodechange(Source As Notesuidocument)
If source.editmode Then
Call source.FieldSetText(“AllowClose”,”0″)
Call source.fieldSetText(“SaveOptions”,”1″)
If Not source.IsNewDoc Then
If  Ucase(source.FieldGetText(“Status”))<>”CANCELED” Then
Call source.fieldSetText(“CancelFlag”,””)
End If
End If
End If
End Sub

The QueryClose event will look like this:
Sub Queryclose(Source As Notesuidocument, Continue As Variant)
Continue = True
If source.FieldGetText(“AllowClose”) “Status”)<>”CANCELED”) Then
Msgbox “Sorry, you must use the Action buttons to close this form”,,”Unable to Continue”
continue = False
Else
If Ucase(source.FieldGetText(“Status”)=”CANCELED”) Then
If  Ucase(source.fieldgettext(“CancelFlag”)) <>”YES” Then
Msgbox “Sorry, you need to use the CANCEL action button to cancel this request”,,”Unable to Close”
continue = False
End If
End If
End If
End Sub

Your Cancel Button formula should be this:

Answer:=@Prompt([YesNo]; “Cancel This SSR?”; “This SSR and all actions will be deleted”);
@If(Answer!=1;@Return(“”);””);
FIELD Status := “Canceled”;
FIELD CancelFlag:=”YES”;
FIELD AllowClose:=”1″;
FIELD SaveOptions:=”1″;
@If(@Command([FileSave]);
@Do(
@SetField(“SaveOptions”;”0″);
@Command ([CloseWindow]))
;””)

Similarly, you could code your SAVE and CLOSE button:
FIELD AllowClose:=”1″;
FIELD SaveOptions:=”1″;
@If(@Command([FileSave]);
@Do(
@SetField(“SaveOptions”;”0″);
@Command([FileCloseWindow]))
;””)

Hee, hee.. be warned… if you don’t have the QueryClose event coded exactly right, you will have to kill notes in order to exit the form.  So you might want to unhide your AllowClose, CancelFlag, and SaveOptions field while you are testing.

Setting the “SaveOptions” to “1” before the save, and then to “0” after the save eliminates the “Do you want to save” dialog box.

See if this helps,