舉例為帳號申請單,在開單的時輸入一個帳號,系統判斷該帳號是否存在於系統中。
1.在表單的JS Header中寫判斷的javascript函數:
var request;
function checkloginname(){
request = new ActiveXObject("Msxml2.XMLHTTP")
if (!request){
request=new ActiveXObject("Microsoft.XMLHTTP");}
request.onreadystatechange=aftercheckloginname;
//這裡假設資料庫路徑為mis/accounts.nsf,且表單中輸入帳號的域是account,將這個域的值傳遞到代理中
url="/mis/accounts.nsf/checkRepeatId?openagent&Id="+document.forms[0].account.value;
request.open("post",url,true);
request.send(null);
}
function aftercheckloginname(){
if (request.readystate==4){
if (request.status==200){
if (request.responseText.indexOf("1")>-1){
alert (" 對不起,該帳號已經被使用!");
document.forms[0].account.value="";
document.forms[0].account.focus();
}
}
}
}
2.建立一個checkRepeatId的代理:
Sub Initialize
Dim ss As New NotesSession
Dim doc,docx As NotesDocument
Dim view As NotesView
Dim db As NotesDatabase
Set doc=ss.DocumentContext
Set db=ss.CurrentDatabase
Set view=db.GetView("checkid") '這個試圖即為帳號的試圖,試圖第一列為帳號
macro=|@RightBack(Query_String_Decoded;"=")| '這句是擷取從URL傳過來的參數
id=Evaluate(macro,doc)
Set docx=view.GetDocumentByKey(id(0),True)
Print "Content-type: text/xml"
If Not docx Is Nothing Then
Print "1"
Else
Print "0"
End If
End Sub
3.在表單中輸入帳號的域,這裡舉例為account,在域的onchange或者onblur事件中調用javascript方法checkloginname()