logo

What to do after deleting a document

What do you do after a user has deleted a document. One option is to do nothing and let Domino return the message "Document Deleted" and then let the user work out what to do next. Not a good idea. I'm going to try and describe a preferrable alternative to this.

Using the Notes client a user would be used to deleting a document and then being returned to the view they were in when the document was opened. After all, do they really want to see a message telling them what they know they just did. This article is going to show how you can return the user to a view (or any URL you like for that matter) after they've deleted a document.

Creating a delete document link

In the browser we can use a hotspot with the @Command([EditClear]) formula to create a link to delete a document. The problem with this link is that we have no control over it. We are going to have to generate the link ourselves. I describe how to do this in more depth in this article. The difference here is that we need to add a little bit to the end. The URL we are going to create is going to have a query string parameter something like:

?DeleteDocument&NavigateTo=../Appointments%3FOpenView

Notice we have used the URL-Encoded version of ? (%3F) so as not to confuse domino as to which bit is the query string.

So to create the above link using Computed-Text the formula would be:

@If(@IsNewDoc; ""; "<a href=\"" + @Text(@DocumentUniqueID) + "?DeleteDocument&NavigateTo=../Appointments%3FOpenView\">Delete Document...</a>")

You could also use a combination of @Formulae in order to compute a value for the URL to navigate to that depends on some value in the document.

Creating the redirect form

Here we are going to make use of the $$ReturnDocumentDeleted form from the article I mentioned above. When a document is deleted domino checks for this form and, if it exists, displays it to the user. We are going to use this form to redirect them to the required URL. This is going to use a method I discussed in this article that uses the meta-tags to do a redirect.

In the HTML Head Contents for your $$ReturnDocumentDeleted form place the following formula:

pos:=@Member( "NavigateTo"; ArgNames );
url:=@If( pos>0; @Subset(@Subset(ArgValues; pos); -1); @Return("") );
"<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=/" + url + "\">"


Before you can get this formula to work you will need to do this to get the ArgNames and ArgValues fields on your form.

The beauty of this approach is that you have the option of whether or not to redirect the user. If there is no NavigateTo parameter in the URL then the form will simply display and you can use this to display some standard message about the document having been deleted. When you do want to redirect you just stick the URL on the end of the query string...


Feedback

  1. Confirmation

    Nice approach...one nice addition to this would be to add some sort of delete confirmation (Are you sure you want to delete this document?) before the delete takes place. I have done this using javascript placed in the HEAD CONTENT section which uses the window.confirm()

    Here's my code as an example: <Script> function deleteDoc(form) { if(confirm(\"Are you sure you want to DELETE? click \'OK\' to delete or \'Cancel\' to abort\")) { location.assign(\""+Path_Translated + @Text(@DocumentUniqueID)+"?DeleteDocument&"+form+"\") } }</SCRIPT>

    Just an idea...then not only do you decide whether and how to redirect the user, you give them the familiar windows style confirmation as well

    1. Re: Confirmation

      Woops. Didn't realise I had missed that out.... I know what you mean. As a developer I would never have a "deletedocument" link on a page without a confirm. Silly me!

      What I usually do is add the following to the link itself in the onclick event:

      onclick="return confirm('Are you sure you want to delete this document?');"

      Jake -CodeStore

  2. Another way to make a redirect form

    To make a cross-brower redirect form you can use the javascript Location.replace method instead of the meta tag wich on Netscape allows the user to press the back button and be redirected and so on... For example : pos:=@Member( "NavigateTo"; ArgNames ); url:=@If( pos>0; @Subset(@Subset(ArgValues; pos); -1); @Return("") ); "<script>window.location.replace(\'"+url+"\')</script>" This method is a very good tip to redirect user without adding the redirect page to the browser history like location.href does.

    1. Re: Another way to make a redirect form

      Great tip all the way, and i do like the script solution better than meta. Nice job guys, keep it up!

      regads LeffeP

  3. THANKS!!

    Thanks man!! This redirect solution is perfect. I was stuck with this redirecting problem for about a week!! You made me sooo happy!! Thanks

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:



Navigate other articles in the category "Forms"

« Previous Article Next Article »
Creating your own field properties   Control what gets printed from the web

About This Article

Author: Jake Howlett
Category: Forms
Keywords: delete; redirect; head;

Options

Feedback
Print Friendly

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »