这是我编写的示例脚本。
任务: - 如果用户尚未在系统上注册为成员,则创建弹出消息以显示用户。
- 用户必须在注释视图“按名称显示的员工信息”中有名称
- 如果用户在视图中有名称,它将向审阅者写一条消息,以通知审阅他们要求的内容。
- 如果用户在“按姓名显示的员工信息”视图中没有姓名,它将弹出一条消息告诉用户该做什么。
// address book
var db:NotesDatabase = session.getDatabase("websvr/pcs", "names", false);
var vw2:NotesView = db.getView("($VIMPeople)");
var dc2:NotesDocumentCollection = vw2.getAllDocumentsByKey(document1.getItemValue("Name"),true);
var doc2:NotesDocument=dc2.getFirstDocument();
while (doc2!=null){
sname=doc2.getItemValueString('LastName')
doc2=dc2.getNextDocument();
}
// end of address book
//current database
var vw:NotesView = database.getView("Staff Information By Name");
var doc:NotesDocument = vw.getDocumentByKey(sname, true);
//check whether have setting on reviewer for current user else will be hard code to specific person
if (doc!=null)
{
revname=doc.getItemValueString("Reviewer")
rev=doc.getItemValueString("ReviewerEmail");
//set Email
var maildoc:NotesDocument=database.createDocument();
var body=maildoc.createMIMEEntity();
var stream=session.createStream();
var content="Dear "+revname+",<br></br>"+
"Please click <a href='http://"+applicationScope.hostname+"/"+(applicationScope.dbfilepath).replace(/(\\)/g, "/")+"/"+
"RequisitionForm.xsp?databaseName="+applicationScope.serverCN+"!!"+
applicationScope.dbfilepath+"&documentId="+
document1.getDocument().getUniversalID()+
"&action=editDocument'>here</a> to view it if you are in a web browser (eg: Internet Explorer, Mozilla Firefox, Google Chrome etc.)"+
"<br /><br /><b>OR</b><br /><br />"+
"<a href='"+document1.getDocument().getNotesURL()+"'>here</a> if you are in the Notes Client. Thank you.";
stream.writeText(content);
body.setContentFromText(stream, "text/html; charset=iso-8859-1", 0);
maildoc.replaceItemValue('Subject', 'Kindly review this '+document1.getItemValueString('Item')+' request by '+document1.getItemValueString('Name')+" on "+I18n.toString(@Today(), 'dd/MM/yyyy'));
maildoc.send(rev);
document1.replaceItemValue("TotalCost",document1.getValue("Cost")*document1.getValue("Qty"));
document1.replaceItemValue("Status","Pending");
document1.save();
context.redirectToPage("/MyRequisition.xsp");
}
else
{
a = 'alert("You do not have access right, please contact admin to register!")' ;
view.postScript(a);
break;
}
在其他页面上工作的示例脚本:
a = 'alert("The applicant details must be unique!")' ;
b = 'alert("Applicant Details inserted!")' ;
var vw:NotesView = database.getView("Staff information by Name");
var doc:NotesDocument = vw.getDocumentByKey(getComponent("Name").getValue(), true);
if (doc!=null){
view.postScript(a);
break;
}
else
{
var newDoc = database.createDocument();
newDoc.appendItemValue("Form", "Staff Form");
newDoc.appendItemValue("Name", getComponent("Name").getValue());
newDoc.appendItemValue("Designation", getComponent("Designation").getValue());
newDoc.appendItemValue("Department", getComponent("Department").getValue());
newDoc.appendItemValue("Reviewer", getComponent("Reviewer").getValue());
newDoc.appendItemValue("Email", getComponent("Email").getValue());
newDoc.appendItemValue("ReviewerEmail", getComponent("ReviewerEmail").getValue());
newDoc.save();
getComponent("Name").setValue("");
getComponent("Designation").setValue("");
getComponent("Department").setValue("");
getComponent("Reviewer").setValue("");
getComponent("Email").setValue("");
getComponent("ReviewerEmail").setValue("");
view.postScript(b);
}