View member feedback to this tip.
Have you ever wanted to redirect a user to a different page based on what document has been deleted in the database?
Code
1. Create button that will execute
JavaScript function deleeDoc() (this will
prompt users if they want to delete
document) :
function deleteDoc(){
if ( confirm ("Are you sure you want to
delete this document?")) {
window.location="http: / /
yourServer/YourDB.nsf/
(LookUpView) /" +
document.all.item("documentUNID").value +
"?deleteDocument&PageNameForRederection" }
}
2. Create computed for display field with
formula:
"[<INPUT TYPE=HIDDEN NAME =
"documentUNID" VALUE="" +
@Text(@DocumentUniqueID) + "">]"
This will store your document UNID
which can be used by JavaScript.
3. Finally, create $$ReturnDocumentDeleted
form and place this JavaScript in the onLoad event:
arg = document.URL;
pos = arg.indexOf("&");
page = arg.substring(pos+1,arg.length);
setInterval("Countdown(page)", 1000)
Place this script in JSHaeader
function Countdown(page){
window.location="http: / /
yourServer/yourDB/" + page +
"?OpenPage"
}
You can place animated gif in the $$ReturnDocumentDeleted (broom or garbage can) and you can also control how long $$ReturnDocumentDeleted will be displayed by modifying parameter in setInterval.
Please make sure that you create Lookup view with first sorted column with formula @Text(@DocumentUniqueID).
This will only work if user opens document in edit mode. If you want to delete document in read mode replace step 1 and 2 with:
1. Create button that will execute JavaScript
function deleeDoc()- this will prompt users if
they want to delete document :
function deleteDoc()
{
if ( confirm ("Are you sure you want to
delete this document?"))
{
var temp = document.forms[0]
temp.butDelete.click()
}
}
2. Create div tag with delete button,
which executes formula (div tag hides
button but it can be executed by JavaScript)
<div id = '@formulaButton'
style='display:none'>
Your button goes here
</div>
Here is the formula for button:
@URLOpen("http: / /yourServer/
yourDB.nsf/ (DeleteLookup) /" +@Text
(@DocumentUniqueID) + "
?deleteDocument&ViewName")
name button butDelete (HTML TAG,
Name propriety)
3. Step 3 is the same as in the
previous section.
You can redirect users to different pages based on document status For example if document has status field, based on its value you can pass different page parameter to $$ReturnDocumentDeleted form.
MEMBER FEEDBACK TO THIS TIP
A neat tip that will be handy if deletion of docs allowed by Web users. However, a view sorted by doc UNID is not required when accessing a document via its UNID. Any view name can be used in the URL, even a non-existant view name -- so use something short like '0'.
-- T Brooks
********************************************
Good tip, another way to simplify the JavaScript for the URL would be:
var hostname = location.href.split('.nsf');
arg = document.URL;
pos = arg.indexOf("&");
page = arg.substring(pos+1,arg.length);
setInterval("Countdown(page)", 1000)
Place this script in JSHeader:
function Countdown(page){
window.location= hostname[0] +
".nsf/" + page + "?OpenPage"
}
-- Trevor W.
Do you have comments of your own? Let us know.