Borrar un documento

cancel
Showing results for 
Search instead for 
Did you mean: 
feevalencia
Member II

Borrar un documento

Hola a todo,

quiero ejecutar un script para borrar un documento, el script es el siguiente

var logFile = companyhome.childByNamePath("prueba.xls");
if (logFile != null)
{
document.remove();
}

pero no me borra el documento Smiley Sad , que estoy haciendo mal

ayuuuuuuudaaa por favor
5 Replies
baskeyfield
Member II

Re: Borrar un documento

Hola,

¿Te funciona esto?

removeNode(companyhome.childByNamePath("prueba.xls"));

Tu codigo no funciona porque finalmente lo que borras es "document", y document es el objeto sobre el cual estás aplicando el script, no "prueba.xls" que supongo que es el documento que quieres borrar.

Mirate el api (para alfresco 3.2):

http://wiki.alfresco.com/wiki/3.2_JavaScript_API

Saludos.
feevalencia
Member II

Re: Borrar un documento

Muchas gracias
Lo pruebo ahora y te digo como me ha ido Smiley Wink
feevalencia
Member II

Re: Borrar un documento

No me va Smiley Sad , me da el siguiente error

11:52:00,062 ERROR [org.quartz.core.ErrorLogger] Job (jobGroup.jobD threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: org.alfresco.scripts.ScriptException: 07020038 Failed to execute script 'workspace://SpacesStore/97ab12ee-df78-49ba-b6a0-337034ac9666': 07020037 ReferenceError: "removeNode" is not defined. (workspace://SpacesStore/97ab12ee-df78-49ba-b6a0-337034ac9666#6)]
   at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
   at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
Caused by: org.alfresco.scripts.ScriptException: 07020038 Failed to execute script 'workspace://SpacesStore/97ab12ee-df78-49ba-b6a0-337034ac9666': 07020037 ReferenceError: "removeNode" is not defined. (workspace://SpacesStore/97ab12ee-df78-49ba-b6a0-337034ac9666#6)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:228)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:187)
   at sun.reflect.GeneratedMethodAccessor518.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:147)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy189.executeScript(Unknown Source)
   at org.alfresco.repo.action.executer.ScriptActionExecuter.executeImpl(ScriptActionExecuter.java:170)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:127)
   at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:711)
   at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:648)
   at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:510)
   at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:498)
   at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:719)
   at sun.reflect.GeneratedMethodAccessor515.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:147)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy25.executeAction(Unknown Source)
   at org.alfresco.repo.action.scheduled.AbstractScheduledAction$JobDefinition$1$2.execute(AbstractScheduledAction.java:574)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:327)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:234)
   at org.alfresco.repo.action.scheduled.AbstractScheduledAction$JobDefinition$1.runTransactionalAction(AbstractScheduledAction.java:564)
   at org.alfresco.repo.action.scheduled.AbstractScheduledAction$JobDefinition$1.doWork(AbstractScheduledAction.java:432)
   at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:514)
   at org.alfresco.repo.action.scheduled.AbstractScheduledAction$JobDefinition.execute(AbstractScheduledAction.java:398)
   at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
   … 1 more
baskeyfield
Member II

Re: Borrar un documento

El "removeNode" tienes que ejecutarlo sobre alguna variable tipo "scriptNode". Por ejemplo ejecútalo así:

companyhome.removeNode(companyhome.childByNamePath("prueba.xls"));

Saludos.
feevalencia
Member II

Re: Borrar un documento

Ahora si que me funciona, muchisimas gracias