cancel
Showing results for 
Search instead for 
Did you mean: 

Problems copying a document to several userHome

nimbus1958
Confirmed Champ
Confirmed Champ

I have a document with a custom type.

One of those properties allow for the userNames of several users separated by space.

A script reads these userNames and copy the document to the relevant userHome space.

It works fine if I have only one user.

When I have two or more, I get errors.

Using the javascript console, I can see (via logger.log) the different userNames and the userNode but the moment I do a "document.copy(userNode), it crashes!

Anybody would have an idea?

Thanks,

Pablo

1 ACCEPTED ANSWER

Solved! But I don't know why!

I remove all the "Logger.log" and voila! It all works now!

Thank you Abbas for taking the time to answer!

View answer in original post

7 REPLIES 7

nimbus1958
Confirmed Champ
Confirmed Champ

I get the following error:

500 Internal Error Stacktrace-Details: org.springframework.extensions.webscripts.WebScriptException: 03252579 Wrapped Exception (with status template): null at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1138) at de.fme.jsconsole.ExecuteWebscript.executeScriptContent(ExecuteWebscript.java:405) at de.fme.jsconsole.ExecuteWebscript.access$100(ExecuteWebscript.java:56) at de.fme.jsconsole.ExecuteWebscript$2.execute(ExecuteWebscript.java:280) at de.fme.jsconsole.ExecuteWebscript$2.execute(ExecuteWebscript.java:273) at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:464) at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:352) at de.fme.jsconsole.ExecuteWebscript.runWithTransactionIfNeeded(ExecuteWebscript.java:272) at de.fme.jsconsole.ExecuteWebscript.access$000(ExecuteWebscript.java:56) at de.fme.jsconsole.ExecuteWebscript$1.doWork(ExecuteWebscript.java:250) at de.fme.jsconsole.ExecuteWebscript$1.doWork(ExecuteWebscript.java:247) at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:555) at de.fme.jsconsole.ExecuteWebscript.runScriptWithTransactionAndAuthentication(ExecuteWebscript.java:247) at de.fme.jsconsole.ExecuteWebscript.execute(ExecuteWebscript.java:121) at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:467) at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:656) at org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:428) at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:308) at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:399) at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:210) at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.alfresco.module.aosmodule.service.ContextRootFilter.doFilter(ContextRootFilter.java:93) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:68) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) at org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:2492) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.NullPointerException at de.fme.jsconsole.CacheBackedChunkedList.get(CacheBackedChunkedList.java:49) at de.fme.jsconsole.CacheBackedChunkedList.get(CacheBackedChunkedList.java:16) at java.util.AbstractList$Itr.next(AbstractList.java:358) at java.util.AbstractCollection.toArray(AbstractCollection.java:141) at java.util.ArrayList.<init>(ArrayList.java:177) at de.fme.jsconsole.JavascriptConsoleScriptObject.getPrintOutput(JavascriptConsoleScriptObject.java:168) at de.fme.jsconsole.ExecuteWebscript.executeScriptContent(ExecuteWebscript.java:352)

Basicaly, I have a NPE and I cannot see where!

abbask01
Star Collaborator
Star Collaborator

how do you find userHome space? can you check if userNode is null without executing the copy action

please upload your script

Regards,
Abbas

Hello Abbas,

Here is my script (in work mode!)

var user = document.properties["mr:User"];
logger.log(user);
var n = (user.split(" ").length - 1);
logger.log(n);

if (n === 0) {
var person=people.getPerson(user);
var mailAdr=person.properties.email;
logger.log(mailAdr)
var userNode = companyhome.childByNamePath("/User Homes/" + user);

var ref = userNode.nodeRef;
ref = "https://www.nirond-doc.net/share/page/repository#filter=path%7C%2FUser%2520Homes%2F" + user + "&page=1";
logger.log(ref);

document.copy(userNode);


function sendMail()
{
var mail = actions.create("mail");
mail.parameters.to = mailAdr;
mail.parameters.subject = "New (snail)mail";
mail.parameters.from = "mailroom@nirond.be";
mail.parameters.text = "The following mail is available: " + document.name + " in " + ref;
mail.execute(document);
}
sendMail();

} else {
var num = (user.split(" ").length);

logger.log("num " + num);
var initials = (user.split(" "));
logger.log("initials " + initials);
var i;
for (i = 0; i < num; i++) {
logger.log(i);

var ref;
var refer;
var userNode;

var initCode = "ini" + i;

var initial = initials[i];
logger.log("initial " + initial);

var person=people.getPerson(initial);
var mailAdr=person.properties.email;
logger.log(mailAdr);

var userNode = companyhome.childByNamePath("/User Homes/" + initial);
logger.log(userNode);

var refer = "https://www.nirond-doc.net/share/page/repository#filter=path%7C%2FUser%2520Homes%2F" + initial + "&page=1";

/*document.copy(userNode);
/*
function sendMail()
{
var mail = actions.create("mail");
mail.parameters.to = mailAdr;
mail.parameters.subject = "New (snail)mail";
mail.parameters.from = "mailroom@nirond.be";
mail.parameters.text = "The following mail is available: " + document.name + " in " + ref;
mail.execute(document);
}
sendMail();
}*/
}
}

It all works until I do the copy(). If I have only one user, no problem!

That is why it is commented out!

Latest news!

I found that the document.copy() does not work when inside a For loop!

I have reduced my script to the following but no success. Same problem!

var user = document.properties["mr:User"];

var init = user.split(" ");

init.forEach(function(initial) {

var person = people.getPerson(initial);
var mailAdr = person.properties.email;

var userNode = companyhome.childByNamePath("/User Homes/" + initial);

document.copy(userNode);
});

If I log the variables, they are all there!

Solved! But I don't know why!

I remove all the "Logger.log" and voila! It all works now!

Thank you Abbas for taking the time to answer!