Question

I have added a button in my email.

On click of the button the following formula runs:

@If(disablebutton="1"; 
    @Return(@Prompt([Ok];"";"Thank you but you have already clicked once! :) "));
    @Prompt([Ok];"";"Thank you for the click! :) "));
@MailSend( "abc@xyz.com"; ""; "" ; "I will be present at the event!" ; 
            "" ; "" ; [PriorityNormal] );
FIELD disablebutton:="1";

Above formula basically does the following:

if(disableButton is 1){
       Open prompt : you have already clicked and return without executing anything ahead
}else{
       Open prompt : Thank you for the click!
}

send email to the specified email address with specified subject

set disableButton = 1

So when the email is opened by the receiver, above formula restricts receiver to click button just once and as a result only one mail gets sent out to specified email address.

However, the issue is, if the user closes the mail and opens again, the same formula runs from the beginning which effectively allows receiver to send the mail again.

So effectively he can send as many mails to the specified email address by closing and opening the mail and clicking the button afresh.

How to deal with this ? I want the value of disableButton to persist permanently so that the mail gets sent out only once.

Was it helpful?

Solution

Put the following lines at the end of your formula:

@If(@IsDocBeingEdited;
    @PostedCommand([FileSave]);
    @Do(    @PostedCommand([EditDocument]);
            @PostedCommand([FileSave]);
            @PostedCommand([EditDocument])))

Field setting keeps staying in document only if document is in edit mode and it gets saved. Usually, emails are in read mode when users read their emails. With @Command([EditDocument]); you can toggle between read and edit mode.

If the email is in edit mode we just need to save the document.

If the email is in read mode we change document to edit mode, save the document and set it back to read mode.

OTHER TIPS

Try to implement the same functionality in LotusScript. It's much easier - to debug - there.

dim uiws as new notesuiworkspace
dim uidoc as notesuidocument
dim disablebutton as string
dim doc as notesdocuemnt
set uidoc = uiws.currentDocument
disablebutton = uidoc.fieldgettext("DisableButton")
if(strcompare(disablebutton,"1",5)=0 then
messagebox {Thank you but you have already clicked once! :)}
else
call sendMail(uidoc.document)
set doc =uidoc.document
call doc.replaceitemvalue("DisableButton","1")
call doc.save(true,false)
call uidoc.close()
end if

The function SendMail needs to be implemented too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top