我正在使用此代码处理存档应用程序:
var arcName:String = "Archives/" + aDBName + "-Backup-" + toDay + "-" + thisTime.slice(0,5);
var server:String = appDB.getServer();
var arcDB:NotesDatabase = appDB.createCopy(server, arcName);
arcDB.setTitle("This is a Test");
但它在arcDB.setTitle失败 - 创建了数据库的新副本,因此没有问题。
这来自IBM知识库:
var db2:NotesDatabase = db.createCopy(null, "names2");
db2.setTitle("Copy of names");
我无法看到这两段代码之间的区别。 我错过了什么吗?
答案 0 :(得分:4)
通常当某些东西不能与数据库或设计对象相关的XPage时,我检查的第一件事是最大的互联网名称和密码访问https://stackoverflow.com/a/23045860/1187943
或改变所以我使用sessionAsSigner或sessionAsSignerWithFullAccess进行工作
答案 1 :(得分:1)
如果您不关心effectiveUser对源数据库的访问权限,他们创建副本的权限以及他们在目标Domino服务器上创建NotesDatabase的访问权限,那么我绝对不会反对Fredrik建议使用sessionAsSigner / WithFullAccess。
此外,我发现最佳做法是使用try / catches(帮助进行故障排除和errorHandling),对象测试(访问NotesDatabase时的.isOpen()),以及返回可由调用函数读取的Object。 / p>
以下是一些可能有用的示例代码:
var copyNotesDatabase = function(dbName) {
var isSuccessful = true;
var responseMessage = "";
try {
//set appDB using dbName from function arguments
var appDB = session.getDatabase(session.getServerName(),dbName);
//var appDB = sessionAsSigner.getDatabase(session.getServerName(),"sourceDb.nsf");
//var appDB = sessionAsSignerWithFullAccess.getDatabase(session.getServerName(),"sourceDb.nsf");
if(appDB.isOpen()) {
var arcName:String = "Archives/" + aDBName + "-Backup-" + toDay + "-" + thisTime.slice(0,5);
var server:String = appDB.getServer();
//arcDB will be created based on appDB permissions, ie effectiveUser, or sessionAsSigner, etc.
var arcDB:NotesDatabase = appDB.createCopy(server, arcName);
if(arcDB.isOpen()) {
arcDB.setTitle("This is a Test");
responseMessage = "Successfully copied NotesDatabase!"
} else {
isSuccessful = false;
responseMessage = "Unable to open copied NotesDatabase.";
}
} else {
isSuccessful = false;
responseMessage = "Unable to open source NotesDatabase.";
}
} catch(e) {
print("Error from SSJS: " + e);
isSuccessful = false;
responseMessage = e;
}
return { status : isSuccessful, message : responseMessage };
}
使用此功能,您可以执行以下操作:
function makeCopy(appName) {
var fObj = copyNotesDatabase(appName);
if(fObj.status) {
return "Successfully copied " + appName;
} else {
return fObj.message;
}
}
...至少,使用try / catch并返回错误至少会告诉您为什么当前代码无效。希望这有帮助!