我刚刚使用 Javascript API 编写了一个脚本,因此我可以将其用作空间规则。每当文档进入空间时,它基本上都会检查文档的名称以获取将存储该文档的父目录(文档的名称包含父文件夹的名称),然后创建 future 的父目录(如果不存在),最后移动将文档放入其中。
我在执行最后一步时遇到了麻烦。每当我尝试将文档移动到最近创建的文件夹中时,都会收到以下错误:
Node has been pasted into its own tree.
这是我到目前为止的代码,我认为它几乎是自动描述的:
var fileName= document.properties.name;
var fields = fileName.split('.');
var parentName= fields[0];
var newNode=space.childByNamePath(parentName);
if (newNode === null) { //create folder and move document into it
newNode=space.createFolder(parentName); //works
document.move(newNode); //I'm getting the error here
}else{ //folder already exists, just move document into it
document.move(newNode); //here too
}
如果我注释掉 document.move(newNode); 行,其他一切都会正常工作。父文件夹已成功创建,但显然文档仍存储在当前空间的根目录下,这不是我需要的。事实上,我需要将其移至实际文件夹中。
我做错了什么吗?任何帮助将非常感激。谢谢。
更新: 事实上,我发现 move() 在 if 范围内调用,如果我注释掉 else 范围内的其他调用。因此,错误是在 else move() 调用时引发的。另外,如果我删除 else 子句并在 if 作用域之后仅放置一个 move() 调用,它也会产生同样的错误。
最佳答案
您应该将规则作为后台进程运行,它将解决问题(“在后台运行规则”选项)。
关于javascript - 无法使用 Alfresco 的 Javascript API 将节点移动到其自己的树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45503232/