Link to home
Create AccountLog in
Avatar of smithajohn
smithajohn

asked on

After deleting a document in a view, how to redirect the page to the view>

Hi,
   I open a document in a view and delete it with an Action button. The code in the button is @Command([EditClear]). It deletes the document. My problem is, it gives me a page saying 'Deleted'. But I want the parent view to be displayed and refreshed instead of this page. I've a $$Return field in the form which directs the control to the view. But it works with Submit action only.
 Thanks in advance
Avatar of Bozzie4
Bozzie4
Flag of Belgium image

Yes, you can use another $$ field  for this.

$$ReturnDocumentDeleted

This is from designer help :
Adding the message field
Create one of the following fields to hold the error message:
An editable text field named MessageString to display the default server-generated error message.
A computed-for-display field whose formula replaces the default error message with a customized message.
For example, this formula for a field named CustomString on a $$ReturnAuthenticationFailure form gives more information to the user if authentication fails. The formula takes the value from the default MessageString field if it contains "unauthenticated" and replaces it with instructions to the user. If the MessageString field does not contain the word "unauthenticated", Domino uses the value of MessageString instead.
@If(@Contains(messagestring;"unauthenticated");"Sorry, the name and password you entered are unknown in our system. If you are new to our site, return to the home page and follow instructions for registering.";messagestring)

Sorry, a FORM named $$ReturnDocumentDeleted (the help text confused me a bit)

cheers,

Tom
Avatar of qwaletee
qwaletee

Hi Bozzie4,

Hmm, I wonder if a simple $$Return would work -- @COmmand([EditClear]); @Command([OpenView]; "default view name")

Best regards,
qwaletee
No that doesn't work , I just tried it.  Maybe if the formula is rewritten to something more complex ...

cheers,

Tom
Avatar of smithajohn

ASKER

Hi Bozzie4,
    I also went thru the help and did the same mistake as you said($$ReturnDocumentDeleted field).
I tried it with $$ReturnDocumentDeleted form. When the doc is deleted succesfully, my MessageString will be empty.
I've given ' @If(MessageString="" ; "http://.../"viewname"?Openview" ; MessageString) ' in the formula field. Is this the way?
Instead of the "Deleted" page it gives me a page with a link to the View. I tried @Command([OpenView]) in the @If , but it doesn't work.
Any way to to goto the view directly as in $$Return field?
thanks..
What might work better for you...

Instead of using a button with the @Command, use a link to the following computed URL:
    "/" + @ReplaceSUbstring(@Subset(@DbName;-1); " " : "\\"; "+" : "/") + "/DeleetDocument?OpenAgent&" + @Text(@DocumentUniqueID)

Create an agent:
    named DeleteDocument
    Shared
    set to run with web user's rights
    Run against No target or Run Once (@Commands may be used)
    Using LotusScript
    Place the following code in Initialize

Dim s as new notesSession
Dimc control as notesDocument, db as notesDatabase, target as notesDocument, pos as integer,insruct as String
Set control = s.documentContext
Set db = s.currentDatabase
instruct = control.Query_String(0)
pos = Instr(instruct,"&")
If pos = 0 Then
    Print "Missing document delete instruction"
    Exit Sub
End If
instruct = Mid$(instruct,pos+1)
If Len(instruct) <> 32 Then
    Print "Invalid document delete instruction"
    Exit Sub
End If
On Error Resume Next
Set target = db.getDocumentByUnid(instruct)
If Err <> 0 Then
    Print "Unknown document delete instruction " Erl Err Error
    Exit Sub
End If
target.Remove
If Err <> 0 Then
    Print "Failed document delete instruction " Erl Err Error
Else
    Print "[..]" 'redirect to database home page
End If



Or put this in the htmlhead section of the Form :

"<meta http-equiv=\"refresh\" content=\"1;url=/"+ @webdbname++"/theview?openview\">"

This will redirect the user automatically to the view.  Not a perfect solution, but at least easy to do :-)


cheers,

Tom
Well, heck, you could just give the "$$ViewTemplateFor [main view name]" form an alias -- $$ReturnDocumentDeleted

Wouldn't that be even simpler?
qwaletee ,
       Loads of thanks for that. The agent is working fine.

Bozzie4,
     The HTML head code doesn't seem to be working. It will take the control back to the view even before I click the "Delete' button.
and in the load event of $$ReturnDeleteDocument , u can give location.href="...?openview". It will also redirects to the view instead of giving the link(when u use the computed field and Messagestring, it gives a page with a link to the view).

      But there is another bottleneck now...I want to give this delete option in many views. How do I get the viewnames in a global variable? so that I can use this variable in the agent.
I tried it in the Global section of the view(getview). But it returns an empty string.
I invoke the views thru Hotspont links from the navigation page.

Will give another 100 points for this....

thanks.
 
ASKER CERTIFIED SOLUTION
Avatar of qwaletee
qwaletee

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
thanks, I'll try it out....
Thanks   qwaletee ....
So you get 125+100=225 points !!