我正在为 Alfresco 社区编写一个简单的 javascript 脚本。每次上传新文件时我都会运行脚本。
我需要检查文件夹中是否存在特定文件名(label.txt)。如果存在,我将使用该文件中包含的信息进行后续处理。
如果我单独设置文件名,只要文件夹本身是指定脚本的文件夹,它就可以正常工作。
var labelFile = space.childByNamePath("label.txt");
if (labelFile != null)
{
...
}
当我将脚本的继承设置为较低级别的文件夹时,脚本会运行,但仍尝试在根文件夹中查找 label.txt
文件。我正在尝试找到上传文档的实际路径:
var dpath = document.displayPath + "/label.txt";
var labelFile = space.childByNamePath(dpath);
logFile.content += "labelFile: " + labelFile.displayPath + "\r\n";
if (labelFile != null)
{
...
}
我在 dpath var 中得到了一个据称正确的路径,但我在文件对象上得到了 NULL 结果,因此我无法读取文件及其内容。
我做错了什么?
最佳答案
那里的“空间”是什么?尝试使用“companyhome”,请参阅此以获得更多想法。 http://docs.alfresco.com/4.0/references/API-JS-rootscoped.html
The current space ScriptNode (if any). For a script executing from a rule, the space object is the space in which the rule resides. If the rule is inherited, this may not be the expected space.
关于javascript - alfresco javascript 继承和路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37528197/