Automatically Deleting documents after XX days

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2009 01:49 PM
Thank you.
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2009 02:27 PM
http://wiki.alfresco.com/wiki/Scheduled_Actions
For what you need, you would configure your scheduled action with a cron statement, a query that finds the documents in the folder that are over 90 days old, and an action that deletes the documents.
You should be able to piece together your Lucene query by looking at examples on the Scheduled Actions wiki page. If not, post a reply back here.
The action you want to execute is the "execute-script" action. You'll tell it to run a piece of JavaScript that resides in "Data Dictionary/Scripts". That JavaScript will use the JavaScript API to delete the document which is just one line:
document.remove()
So, when the scheduled action wakes up, it will fire off the Lucene query to find the old docs, and then it will run the JavaScript against the docs it finds.
Jeff

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2009 05:19 AM
I also have to create a schedule action that delete all documents older than two days but I can't find the correct sintax for the query, can you help me. I post the whole action
<bean id="findoldfiles" class="org.alfresco.repo.action.scheduled.CronScheduledQueryBasedTemplateActionDefinition"> <property name="transactionMode"> <value>UNTIL_FIRST_FAILURE</value> </property> <property name="compensatingActionMode"> <value>IGNORE</value> </property> <property name="searchService"> <ref bean="SearchService"/> </property> <property name="templateService"> <ref bean="TemplateService"/> </property> <property name="queryLanguage"> <value>lucene</value> </property> <property name="stores"> <list> <value>workspace://SpacesStore</value> </list> </property> <property name="queryTemplate"> <value>@cm\:created:${luceneDateRange(-P20D, -P2D)}</value> </property> <property name="cronExpression"> <value>0 0/1 * * * ?</value> </property> <property name="jobName"> <value>jobA</value> </property> <property name="jobGroup"> <value>jobGroup</value> </property> <property name="triggerName"> <value>triggerA</value> </property> <property name="triggerGroup"> <value>triggerGroup</value> </property> <property name="scheduler"> <ref bean="schedulerFactory"/> </property> <property name="actionService"> <ref bean="ActionService"/> </property> <property name="templateActionModelFactory"> <ref bean="templateActionModelFactory"/> </property> <property name="templateActionDefinition"> <ref bean="deleteoldfiles"/> </property> <property name="transactionService"> <ref bean="TransactionService"/> </property> <property name="runAsUser"> <value>System</value> </property> </bean> <bean id="deleteoldfiles" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition"> <property name="actionName"> <value>script</value> </property> <property name="parameterTemplates"> <map> <entry> <key> <value>script-ref</value> </key> <value>${selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/cm:Record_x0020_Management/cm:delete.js"' )}</value> </entry> </map> </property> <property name="templateActionModelFactory"> <ref bean="templateActionModelFactory"/> </property> <property name="dictionaryService"> <ref bean="DictionaryService"/> </property> <property name="actionService"> <ref bean="ActionService"/> </property> <property name="templateService"> <ref bean="TemplateService"/> </property> </bean>
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2013 01:38 AM
Can you tell me the javascript code for this? My javascript is not working it is showing no nodes selected.
Thanks
Nancy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2013 02:39 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2013 02:35 AM
function addMonths(date, months) {
date.setMonth(date.getMonth() + months);
return date;
}
var docs = search.luceneSearch("PATH:\"/app:company_home/st:sites//*\" AND @cm\\:modified:[addMonths(new Date(), -6)]");
for(var dest : docs)
dest.move(C:\Alfresco\alf_data\archive)
and
scheduled-action-services-context.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<!–
Define the model factory used to generate object models suitable for use with freemarker templates.
–>
<bean id="templateActionModelFactory" class="org.alfresco.repo.action.scheduled.FreeMarkerWithLuceneExtensionsModelFactory">
<property name="serviceRegistry">
<ref bean="ServiceRegistry"/>
</property>
</bean>
<!– run the script–>
<bean id="runscript" class="org.alfresco.repo.action.scheduled.CronScheduledQueryBasedTemplateActionDefinition">
<property name="transactionMode">
<value>ISOLATED_TRANSACTIONS</value>
</property>
<property name="compensatingActionMode">
<value>IGNORE</value>
</property>
<property name="searchService">
<ref bean="SearchService"/>
</property>
<property name="templateService">
<ref bean="TemplateService"/>
</property>
<property name="queryLanguage">
<value>lucene</value>
</property>
<property name="stores">
<list>
<value>workspace://SpacesStore</value>
</list>
</property>
<property name="queryTemplate">
<value>PATH:"/app:company_home/st:sites"</value>
</property>
<property name="cronExpression">
<value>0 0/15 * * * ?</value>
</property>
<property name="jobName">
<value>jobA</value>
</property>
<property name="jobGroup">
<value>jobGroup</value>
</property>
<property name="triggerName">
<value>triggerA</value>
</property>
<property name="triggerGroup">
<value>triggerGroup</value>
</property>
<property name="scheduler">
<ref bean="schedulerFactory"/>
</property>
<property name="actionService">
<ref bean="ActionService"/>
</property>
<property name="templateActionModelFactory">
<ref bean="templateActionModelFactory"/>
</property>
<property name="templateActionDefinition">
<ref bean="moveoldfiles"/>
</property>
<property name="transactionService">
<ref bean="TransactionService"/>
</property>
<property name="runAsUser">
<value>System</value>
</property>
</bean>
<!–Execute the script–>
<bean id="moveoldfiles" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
<property name="actionName">
<value>script</value>
</property>
<property name="parameterTemplates">
<map>
<entry>
<key>
<value>script-ref</value>
</key>
<value>${selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:archive.js"' )}</value>
</entry>
</map>
</property>
<property name="templateActionModelFactory">
<ref bean="templateActionModelFactory"/>
</property>
<property name="dictionaryService">
<ref bean="DictionaryService"/>
</property>
<property name="actionService">
<ref bean="ActionService"/>
</property>
<property name="templateService">
<ref bean="TemplateService"/>
</property>
</bean>
</beans>
In my log file it is showing no nodes selected
The problematic instruction is
${selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:archive.js"' )} [on line 1, column 1 in string://fixed]
Please help
Thanks
Nancy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2013 07:28 AM
First problem I see in your xml is I think you have not checked this note
<!– Note - FreeMarker ${..} entries must be escaped in Spring context files –>
in this line
<value>${selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:archive.js"' )}</value>
you need to escape special charactes like "$" , "{" and "}"
so it would be like this
<value>\$\{selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:archive.js"' )\}</value>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2013 01:43 AM
After making the above changes still my documents are not moving from the document library.
In log file it is showing error
ERROR [org.quartz.core.JobRunShell] Job jobGroup.jobA threw an unhandled Exception:
org.alfresco.error.AlfrescoRuntimeException: 05240000 SOLR queries can not be executed while the repository is bootstrapping
Nancy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2013 02:26 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2013 02:54 AM
In alfresco.log there are no errors but in alfrescotomcat-stdout.log it is showing error:
ERROR [solr.tracker.CoreTracker] [SolrTrackerScheduler_Worker-3] First transaction was not found with the correct timestamp.
2013-06-24 12:10:06,081 ERROR [solr.tracker.CoreTracker] [SolrTrackerScheduler_Worker-3] SOLR has successfully connected to your repository however the SOLR indexes and repository database do not match.
2013-06-24 12:10:06,081 ERROR [solr.tracker.CoreTracker] [SolrTrackerScheduler_Worker-3] If this is a new or rebuilt database you SOLR indexes also need to be re-built to match the database.
2013-06-24 12:10:06,081 ERROR [solr.tracker.CoreTracker] [SolrTrackerScheduler_Worker-3] You can also check your SOLR connection details in solrcore.properties.
2013-06-24 12:10:06,081 ERROR [solr.tracker.CoreTracker] [SolrTrackerScheduler_Worker-3] Tracking failed
org.alfresco.error.AlfrescoRuntimeException: 05240000 Initial transaction not found with correct timestamp
at org.alfresco.solr.tracker.CoreTracker.checkRepoAndIndexConsistency(CoreTracker.java:1523)
Nancy
